0

hi I have a piece of code that looks like this in tabular:

\usepackage{mwe} 

\begin{tabular}

(1) & \includegraphics[width=0.2\textwidth]{images/some_image.png} & He thinks:
   $``$Maybe, the food     is in the yellow pot.$"$
  \newline
   But, the yellow pot is empty.\\
\end{tabular}

I have used \newline to move the sentence to the next line, but it does not work. I have tried p{some cm} but the problem is when I add this, two horizontal line tabke lines appear that I do not want, and the text moves under the image.

I would like to keep it in a way that there is an image on the left with it's corresponding text on the right, but if the text is long, it can be moved to the new line similar to the image in : figures on the left with corresponding texts on the right

6
  • Your tabular-Environment is not well-formed: you lack the declaration of your column types, something like \begin{tabular}{lp{30mm}p{30mm}} with the p column type for the third column, you should be able to use \newline inside the tabular.
    – Lupino
    Jul 24, 2020 at 9:48
  • Hi, i had the declaration of column types but they added two horizontal table lines, which I would like to avoid, like the images in tex.stackexchange.com/questions/554582/… Jul 24, 2020 at 9:52
  • Horizontal lines (left-to-right) are usually made with \hline; TeX itself doesn't draw them on its own. Besides that, they are independend on column types. If you mean vertical lines (top-to-bottom), they are indeed defined in the column declaration by a bar |, if you omit those bars, no lines are drawn.
    – Lupino
    Jul 24, 2020 at 9:57
  • these are all the packages i am using, I have not got any indication of \hline anywhere in my document, so I do not know why the lines appear \usepackage[small]{dgruyter} \usepackage{microtype} \usepackage{xcolor} \usepackage{tablefootnote} \usepackage{tabularx} \renewcommand{\tabularxcolumn}[1]{m{#1}} \usepackage[export]{adjustbox} \usepackage{graphicx} \graphicspath{ {./images/} } \usepackage{appendix} \usepackage{gb4e} Jul 24, 2020 at 10:10
  • 1
    Okay, the dgruyter package does a lot of things with tabulars… but it also defines a macro \baretablulars which you can use to swith to standard LaTeX tables (use \layouttabulars to switch back). There is a passage in the package's documentation about that.
    – Lupino
    Jul 24, 2020 at 10:25

2 Answers 2

0

With the help of tabularx in order to make sure the table is as wide as the textwidth and valign=c from adjustbox in order to vertically center the elements:

enter image description here

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{tabularx}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\usepackage[export]{adjustbox}
\begin{document}

\noindent
\begin{tabularx}{\textwidth}{llX}
(1) & \includegraphics[width=0.2\textwidth, valign=c]{images/some_image.png} & He thinks:
   ``Maybe, the food     is in the yellow pot.''  But, the yellow pot is empty.\\
\end{tabularx}

\end{document}

If your table will be longer than a single page, you can use the xltabular package instead. For this, just replace tabularx with xltabular in the above MWE.


For fun, here are two more versions in which each set of image and text is automatically numbered. Version 1 makes use of magicrownumber from Automatic table row numbers while version 2 uses side-by-side minipages inside of an enumerate environment:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{tabularx}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\usepackage[export]{adjustbox}

%%% used in example 1 %%%%%
\usepackage{etoolbox}
\preto\tabular{\setcounter{magicrownumbers}{0}}
\newcounter{magicrownumbers}
\newcommand\rownumber{\stepcounter{magicrownumbers}\arabic{magicrownumbers}}

%%% used in example 2 %%%%%
\usepackage{enumitem}

\begin{document}

\noindent
\begin{tabularx}{\textwidth}{@{\makebox[3em][r]{(\rownumber)\quad}} lX}
\includegraphics[width=0.2\textwidth, valign=c]{images/some_image.png} & He thinks:
   ``Maybe, the food     is in the yellow pot.''  But, the yellow pot is empty.\\
\end{tabularx}

\begin{enumerate}[label={(\arabic*)}]
\item \begin{minipage}{0.2\textwidth} 
        \includegraphics[width=\textwidth, valign=c]{images/some_image.png}
      \end{minipage} 
      \hfill 
      \begin{minipage}{0.7\textwidth} 
        He thinks: ``Maybe, the food is in the yellow pot.'' But, the yellow pot is empty.
      \end{minipage}
\end{enumerate}

\end{document}
6
  • thank you very much for your help, when I compile your code in my document, I get two horizontal table lines, I am using these packages \usepackage[small]{dgruyter} \usepackage{microtype} \usepackage{xcolor} \usepackage{tablefootnote} \usepackage{tabularx} \renewcommand{\tabularxcolumn}[1]{m{#1}} \usepackage[export]{adjustbox} \usepackage{graphicx} \graphicspath{ {./images/} } \usepackage{appendix} \usepackage{gb4e} and I do not know which one is producing the lines. Do you have any ideas? thank you Jul 24, 2020 at 10:11
  • @lulumirzai: Where did you get the dgruyter package from? It does not seem to be available at CTAN and all te other packages you mentioned in your last comment do not cause any horizontal lines to appear.
    – leandriis
    Jul 24, 2020 at 10:18
  • this is a package for book chapter preparation for degruyter publication, if all the other packages are fine, then I probably need to seek for the reason in this one. Thank you very much for your help Jul 24, 2020 at 10:24
  • If you have to stick to the dgruyter package, probably you can make use of the enumetare-based approach in the second MWE I added to my question. Since it does not internally use any tabular or related environments it might work without the added horizontal lines.
    – leandriis
    Jul 24, 2020 at 10:26
  • thanks for the advice Jul 24, 2020 at 10:27
0

enter image description here

The serial number 1 in the begining I have removed just for simplicity sake-- the image is no problem and can be adjusted with the package \usepackage[export]{adjustbox} and by adding valign=c as answered by @leandriis

The right hand side length can be set by taking the longest length and setting it as the column width so that anything longer will flow to the second line automatically

So

\settowidth\colwidth{He thinks: $``$Maybe, the food is in the yellow pot.$"$}

becomes the column width of the second column

Taken from --

https://tex.stackexchange.com/a/512217/197451

\newlength\colwidth
\settowidth\colwidth{He thinks: $``$Maybe, the food is in the yellow pot.$"$}
\begin{tabular}{lm{\colwidth}} 
        \includegraphics[width=0.2\textwidth, valign=c]{example-image} & 
            He thinks: $``$Maybe, the food is in the yellow pot.$"$
    But, the yellow pot is empty.\\
\end{tabular}   

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .