# Easily enforce horizontal space use REPL, if printing

**URL:** <https://discourse.julialang.org/t/easily-enforce-horizontal-space-use-repl-if-printing/31132>\
**Category:** General Usage\
**Created:** [November 15, 2019, 3:56pm UTC](https://discourse.julialang.org/t/easily-enforce-horizontal-space-use-repl-if-printing/31132 "2019-11-15T15:56:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Usor](https://avatars.discourse-cdn.com/v4/letter/u/8dc957/32.png) [@Usor](https://discourse.julialang.org/u/Usor)\
**Post date:** [November 15, 2019, 3:56pm UTC](https://discourse.julialang.org/t/easily-enforce-horizontal-space-use-repl-if-printing/31132/1 "2019-11-15T15:56:59Z")

</div>

If you let something be printed to the REPL, can you enforce that horizontal space is used to the right side of an existing printout?

For example, you have some variables, a small DataFrame and something else; you have printed out the latter; now you want the small DataFrame printed not below it, but next to it; the prompt still moves down as usual (to just below the lowest point of one of those printouts).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 15, 2019, 5:03pm UTC](https://discourse.julialang.org/t/easily-enforce-horizontal-space-use-repl-if-printing/31132/2 "2019-11-15T17:03:45Z")

</div>

I don’t think there is existing functionality for this.

Also, if I understand the requirement correctly, it is not really something the REPL can easily do: `display` is called and you get your prompt back, and _then_ you want to go back and align the new output for the next expression horizontally?

If you just want to place text representations next to each other, you could define a function that calls `show` into an `IOBuffer`, then arranges the results nicely, but you would have to call this explicitly.

---

<div class="post-metadata">

**Author:** ![Usor](https://avatars.discourse-cdn.com/v4/letter/u/8dc957/32.png) [@Usor](https://discourse.julialang.org/u/Usor)\
**Post date:** [November 15, 2019, 5:15pm UTC](https://discourse.julialang.org/t/easily-enforce-horizontal-space-use-repl-if-printing/31132/3 "2019-11-15T17:15:33Z")

</div>

Well, why not? Whatever the details underneath, that would be GREAT functionality 😛

Can you give a small basic example of how to carry out your idea?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 15, 2019, 5:32pm UTC](https://discourse.julialang.org/t/easily-enforce-horizontal-space-use-repl-if-printing/31132/4 "2019-11-15T17:32:30Z")

</div>

Very rudimentary and probably has some bugs:

```julia
function show_side_by_side(io::IO, xs...; gap = 2)
    all_lines = map(x -> split(repr(MIME("text/plain"), x), '\n'), xs)
    widths = map(lines -> maximum(length, lines), all_lines)
    nrows = maximum(length, all_lines)
    nxs = length(all_lines)
    for i in 1:nrows
        for (j, lines) in enumerate(all_lines)
            print(io, rpad(i ≤ length(lines) ? lines[i] : "", widths[j]))
            if j == nxs
                println(io)
            else
                print(io, ' '^gap)
            end
        end
    end
end

show_side_by_side(xs...; gap = 2) = show_side_by_side(stdout, xs...; gap = gap)

```

Eg

```julia
julia> show_side_by_side(ones(2,2), zeros(3, 3))
2×2 Array{Float64,2}: 3×3 Array{Float64,2}:
 1.0 1.0 0.0 0.0 0.0       
 1.0 1.0 0.0 0.0 0.0       
                        0.0 0.0 0.0       

```

---

<div class="post-metadata">

**Author:** ![Usor](https://avatars.discourse-cdn.com/v4/letter/u/8dc957/32.png) [@Usor](https://discourse.julialang.org/u/Usor)\
**Post date:** [November 15, 2019, 5:48pm UTC](https://discourse.julialang.org/t/easily-enforce-horizontal-space-use-repl-if-printing/31132/5 "2019-11-15T17:48:20Z")

</div>

Thank you very much.
