TransWikia.com

Table left, image right in enumerate

TeX - LaTeX Asked by amzon-ex on July 22, 2021

I am trying to place content in an enumerate environment under an item which consists of a table and an image. I wish to place the table to the left and the image to the right (like two objects in different columns of the same table row) but I don’t want the image to hang at the far right position. I want the image to be positioned right next to the table. How do I achieve this? I can’t provide any code because I can’t find the right method to achieve this. The table and image are allowed to be of comparable sizes (heights, to be exact).

EDIT: Here is a rough layout of the same.

enter image description here

3 Answers

Probably the following results in the desired output. Due to the use of [t] at the tabular and valign=t at the includegraphics command, image and table are top aligned. You can of course adjust this if you want to vertically center or bottom align both elements with respect to each other using c or b, respectively.

enter image description here

documentclass{article}

usepackage{graphicx}
usepackage[export]{adjustbox}
usepackage{enumerate}

begin{document}

begin{enumerate}[i]
    item Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    
            begin{tabular}[t]{ll}
                Head 1 & Head 2
                hline
                Foo & Bar 
                Foo & Bar
            end{tabular}
            includegraphics[width=3cm,valign=t]{example-image}

    item Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
end{enumerate}

end{document}

Correct answer by leandriis on July 22, 2021

A rough start point as an example --

Image and table side by side

It uses two minipages (with respectively a width of 60% and 30% of textwidth (so that it remains a 10% margin)) that are embedded in a figure environment in order to make it "float". (You could also use another minipage, or nothing at all.)

The two minipages are vertically centered the one relatively to the other (cf. their [c] argument).

The array (I used tabularx in order to show you its width) use the relative length linewidth in order to define its width: indeed, it must use all the line width of the minipage it is embedded in. Like this, you only have to care about minipages widths.)

Both minipages are separated with the gutter hfill that insert an horizontal "spring" between them.

enter image description here

documentclass{scrartcl}
    usepackage{array,multicol,booktabs,tabularx}
    usepackage{graphicx}
%    usepackage{showframe}

begin{document}
    
    begin{enumerate}
        item ss

begin{figure}[h]
    begin{minipage}[c]{.6textwidth}% or {.6linewidth}, it's the same here
        begin{tabularx}{linewidth}{lX}% caution: here you cannot replace linewidth by textwidth, since within this minipage, linewidth=.6textwidth
            toprule
                Text & Text 
            midrule
                Text & Text 
            
                dots & dots 
            bottomrule
        end{tabularx}
    end{minipage}
    hfill
    begin{minipage}[c]{.3textwidth}
        includegraphics[width=linewidth]{example-image}% caution: here you cannot replace linewidth by textwidth, since within this minipage, linewidth=.3textwidth
    end{minipage}
end{figure}    
item dd  
begin{figure}[h]
    begin{minipage}[c]{.6textwidth}% or {.6linewidth}, it's the same here
        begin{tabularx}{linewidth}{lX}% caution: here you cannot replace linewidth by textwidth, since within this minipage, linewidth=.6textwidth
            toprule
            Text & Text 
            midrule
            Text & Text 
            
            dots & dots 
            bottomrule
        end{tabularx}
    end{minipage}
    hfill
    begin{minipage}[c]{.3textwidth}
        includegraphics[width=linewidth]{example-image}% caution: here you cannot replace linewidth by textwidth, since within this minipage, linewidth=.3textwidth
    end{minipage}
end{figure}    
    end{enumerate}
end{document}

Answered by js bibra on July 22, 2021

I would use a minipage to create the two columns and then add the table in the first minipage and the image to the second one.

documentclass{article}

usepackage{graphicx}
usepackage{tabularx}
usepackage{enumerate}

begin{document}

begin{enumerate}[i]
    item Lorem ipsum dolor sit amet, consectetuer adipiscing elit.%
        begin{minipage}{.5linewidth}
            begin{tabular}{@{}c|c@{}}
                Head 1 & Head 2
                hline
                Foo & Bar 
                Foo & Bar
            end{tabular}
        end{minipage},%
        begin{minipage}{3cm}
            includegraphics[width=3cm]{example-image-a}
        end{minipage}
    item Lorem ipsum dolor sit amet, consectetuer adipiscing elit.%
        begin{minipage}{.5linewidth}
            begin{tabular}{@{}c|c|c@{}}
                Head 1 & Head 2 & Head 3
                hline
                Foo & Bar & Bacon 
                Foo & Bar & Bacon
            end{tabular}
        end{minipage},%
        begin{minipage}{3cm}
            includegraphics[width=3cm]{example-image-a}
        end{minipage}
end{enumerate}

end{document}

example 1


As you are mentioning, that you don't want your picture to appear on the far right, I suppose, that the use of two equally wide minipages is not exactly what your're looking for. Unfortunately, I cannot think of a method that does not require a fixed width. If you want your picture to be next to the table, set a fixed width for the minipage and use the same width for the table (requires tabularx).

documentclass{article}

usepackage{graphicx}
usepackage{tabularx}
usepackage{enumerate}

begin{document}

begin{enumerate}[i]
    item Lorem ipsum dolor sit amet, consectetuer adipiscing elit.%
        begin{minipage}{5cm}
            begin{tabularx}{5cm}{@{}X|X@{}}
                Head 1 & Head 2
                hline
                Foo & Bar 
                Foo & Bar
            end{tabularx}
        end{minipage},%
        begin{minipage}{3cm}
            includegraphics[width=3cm]{example-image-a}
        end{minipage}
    item Lorem ipsum dolor sit amet, consectetuer adipiscing elit.%
        begin{minipage}{5cm}
            begin{tabularx}{5cm}{@{}X|X|X@{}}
                Head 1 & Head 2 & Head 3
                hline
                Foo & Bar & Bacon 
                Foo & Bar & Bacon
            end{tabularx}
        end{minipage},%
        begin{minipage}{3cm}
            includegraphics[width=3cm]{example-image-a}
        end{minipage}
end{enumerate}

end{document}

example 2


Taking the idea of @leandriis, the image would always be right next to the table, no matter how wide or narrow the table is. By this, you don't really have to columns as the images will not be aligned, but as you tated that you want the image to be next to the table, I suppose that this is your expected behaviour. You could just add a horizontal space of 1 em in between the table and the image, so that they don't touch by adding hspace{1em} after the table and before the image. Also with [.5baselineskip] you can add some spacing in between your item text ("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.") and the table/figure.

documentclass{article}

usepackage{graphicx}
usepackage{enumerate}
usepackage[export]{adjustbox}

begin{document}

begin{enumerate}[i]
    item Lorem ipsum dolor sit amet, consectetuer adipiscing elit.[.5baselineskip]%
        begin{tabular}[t]{@{}c|c@{}}
            Head 1 & Head 2
            hline
            Foo & Bar 
            Foo & Bar
        end{tabular}
        hspace{1em}
        includegraphics[width=3cm,valign=t]{example-image-a}
    item Lorem ipsum dolor sit amet, consectetuer adipiscing elit.[.5baselineskip]
            begin{tabular}[t]{@{}c|c|c@{}}
            Head 1 & Head 2 & Head 3
            hline
            Foo & Bar & Bacon 
            Foo & Bar & Bacon
        end{tabular}
        hspace{1em}
        includegraphics[width=3cm,valign=t]{example-image-a}
end{enumerate}

end{document}

example 3

Answered by Sam on July 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP