0

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

6
  • 1
    Hi amzon-ex and welcome to TeX.SE! Could you please provide a scheme of what you're trying to get? I find it quite difficult to understand what exactly you're expecting. – Sam Oct 20 '20 at 15:39
  • 1
    would you like to upload a handrawn sketch of the desired output – js bibra Oct 20 '20 at 15:44
  • @Sam I added a sketch. – amzon-ex Oct 20 '20 at 15:53
  • @jsbibra Added a sketch. – amzon-ex Oct 20 '20 at 15:53
  • 1
    The spacing can be adjusted using \noindent, \hfill, \centering, \quad and \hspace. At the beginning of a line you may need to use \null\hfill or \hspace*{\fill}. – John Kormylo Oct 20 '20 at 16:49
2

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}
1
  • Thank you, very useful! Especially the mention of b and c as modifiers. – amzon-ex Oct 21 '20 at 17:13
2

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}{.5\linewidth}
            \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}{.5\linewidth}
            \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 \\[.5\baselineskip] 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.\\[.5\baselineskip]%
        \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.\\[.5\baselineskip]
            \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

4
  • About the second part of your answer, (it seems quite close to my requirements!) what if I use another blank minipage to create space on the right? Would it work/be an efficient way to do it? – amzon-ex Oct 20 '20 at 17:59
  • 1
    Of course, it would work, but the issue would still be that it does not set the appropriate width automatically. You would still need to define some sort of width to all three minipages, be it a relative one, such as .33\linewidth or an absolute one as 3cm. I think the best approach would be the one proposed by @leandriis. Unfortunately, I didn't think of the most obvious solution, which he surely did. – Sam Oct 21 '20 at 7:28
  • 1
    I chose @leandriis' answer as the right answer for hitting the spot right away, but a big thanks for such a detailed answer and your comments regarding spacing in relation to his answer. – amzon-ex Oct 21 '20 at 17:14
  • 1
    @amzon-ex That's the correct choice! – Sam Oct 22 '20 at 8:02
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.