2

Problem:

Trying to use tabularx to align text to a number of images. I have opened a similar question regarding tabular but decided to open a new specifically for tabularx since the tabular approach generated a number of errors which I could not solve.

Since I have figures I did not know how to make a MWE of them. Instead I will try to explain where the issue is.

Code:

\begin{figure}[tbh]
\begin{tabularx}{\textwidth}{cX}
\includegraphics[scale=.5]{figure8_1_server.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\
\includegraphics[width=.5in]{figure8_1_arrow.eps} & \\
\includegraphics[width=1in]{figure8_1_database.eps} & This is some text that
 describes the second figure. It will take up as much space as is needed 
 and will remain centred. As the text gets longer  it centres in the way 
 that we want. So it seems that this is working. \\
 \includegraphics[width=.5in]{figure8_1_arrow.eps} & \\
 \includegraphics[scale=.5]{figure8_1_table.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\
 \includegraphics[width=.5in]{figure8_1_arrow.eps} & \\
 \includegraphics[scale=.5]{figure8_1_row.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\
 \includegraphics[width=.5in]{figure8_1_arrow.eps} & \\
 \includegraphics[scale=.5]{figure8_1_cell.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.
\end{tabularx}
\caption{Syntax för iterationen for och dess delar.}
\label{fig:database}
\end{figure}

Outputs:

enter image description here

Desired outcome:

To have the text vertically aligned with the photos.

  • You posted no code in your previous question nor did you reply to comments. We can't solve problems with mind reading. – Alan Munn Aug 31 '15 at 0:03
2

You need to set the anchor point for both columns to be at the vertical centre. For the left c-column, which only contains graphics, you can use the key-value

valign=c

which requires adding \usepackage[export]{adjustbox} to your preamble. For the second X-column, use

\renewcommand{\tabularxcolumn}[1]{m{#1}}

Here's your document with a global setting of valign=c for all images in your document:

enter image description here

\documentclass{article}
\usepackage[demo,export]{adjustbox}
\let\oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[2][]{\oldincludegraphics[valign=c,#1]{#2}}

\usepackage{cellspace,tabularx}
\renewcommand\cellspacetoplimit{3pt}
\renewcommand\cellspacebottomlimit{3pt}

\renewcommand\tabularxcolumn[1]{m{#1}}

\begin{document}
\begin{tabularx}{\textwidth}{cX}
  \includegraphics[scale=.5]{figure8_1_server.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\\hline
  \includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
  \includegraphics[width=1in]{figure8_1_database.eps} & This is some text that
  describes the second figure. It will take up as much space as is needed
  and will remain centred. As the text gets longer  it centres in the way
  that we want. So it seems that this is working. \\\hline
  \includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
  \includegraphics[scale=.5]{figure8_1_table.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\\hline
  \includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
  \includegraphics[scale=.5]{figure8_1_row.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\\hline
  \includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
  \includegraphics[scale=.5]{figure8_1_cell.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.
\end{tabularx}

\end{document}
  • Thanks for the answer. I think this works but I'm getting the following error: /test.tex:29: LaTeX Error: Option clash for package adjustbox. - what could be wrong? – kexxcream Aug 30 '15 at 10:00
  • @kexxcream: Remove my demo option, first of all, and try again.. – Werner Aug 30 '15 at 12:00
2

You can use

\renewcommand\tabularxcolumn[1]{m{#1}}

and m column type for first column also like

\begin{tabularx}{\textwidth}{>{\centering\arraybackslash}m{2.2in}X}

to get

enter image description here

You have to adjust 2.2in as you wish. BTW, your table is too long to fit in the page.

\documentclass[svgnames]{article}
\usepackage{tabu,tabularx} % just to show compatibility
\usepackage{array}
\usepackage[demo]{graphicx}

\usepackage{cellspace, makecell}
\renewcommand\cellspacetoplimit{3pt}
\renewcommand\cellspacebottomlimit{3pt}
\usepackage{xparse}

\renewcommand\tabularxcolumn[1]{m{#1}}

\begin{document}
\begin{figure}[tbh]
\begin{tabularx}{\textwidth}{>{\centering\arraybackslash}m{2.2in}X}
\includegraphics[scale=.5]{figure8_1_server.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\\hline
\includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
\includegraphics[width=1in]{figure8_1_database.eps} & This is some text that
 describes the second figure. It will take up as much space as is needed
 and will remain centred. As the text gets longer  it centres in the way
 that we want. So it seems that this is working. \\\hline
 \includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
 \includegraphics[scale=.5]{figure8_1_table.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\\hline
 \includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
 \includegraphics[scale=.5]{figure8_1_row.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\\hline
 \includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
 \includegraphics[scale=.5]{figure8_1_cell.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.
\end{tabularx}
\caption{Syntax för iterationen for och dess delar.}
\label{fig:database}
\end{figure}
\end{document}

I have added \hline just to demonstrate the alignment. Remove them.

  • But the text is not in the middle of the figure, which is what I am requesting. Sorry for not being clear in my text that the text should align center to each image. – kexxcream Aug 30 '15 at 9:13
  • @kexxcream OK, please see the edit. – user11232 Aug 30 '15 at 9:30

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