2

I'm making a list and next to each element of the list I want to put a picture of that element, I'm trying to use tabular, and with that the picture is next to the text, but I want the text to be centered in the middle, not at the bottom of the picture. Here is what I tried:

\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\begin{document}
\begin{tabular}{cc}
  $A_n:\ y^2-x^{n+1}=0$ &  \includegraphics[width=60mm]{images/An szing.pdf} \\
   & \\
  $D_n$ &   \includegraphics[width=60mm]{images/D_n szing.pdf}\\


\end{tabular} \end{document}

And heres what comes out: enter image description here

Any help is appreciated, and also sorry if my question is not well put together, first time here.

Laci
  • 121

2 Answers2

3

With the link indicated by José Carlos Santos, there is an answer from the author of the tabularray package. (It allowed me to see the importance of stretch=0 and the h for image alignment).

How to vertically-center the text of the cells?

The code

\documentclass{article}

% \usepackage[a4paper,vmargin=2cm,hmargin=1cm]{geometry} \usepackage{graphicx} \usepackage{xcolor} \usepackage{tabularray} \begin{document} \noindent \begin{tblr}{ colspec = {X[c,mode=math]Q[c,h]}, stretch = 0, rowsep = 6pt, hlines = {red5, 1pt}, vlines = {red5, 1pt}, } A_n:\ y^2-x^{n+1}=0&\includegraphics[width=0.5\textwidth]{example-image-a}\ D_n &\includegraphics[width=0.5\textwidth]{example-image-b}\ \end{tblr} \end{document}

enter image description here

pascal974
  • 4,652
1

There is a very easy fix to your problem if you load adjustbox with optional [export]. Simply add valign=c to options of \includegraphic and such image will be centred.

In the code, I also redefined columns for convenience: the first to >{$}c<{$} so math expressions no longer required $...$ (requires array package); and the second to p{60mm}. With the latter change, if width is specified as \linewidth, the image will gain optional width equal to its parent column, so the parameter can be change only in one place.

\documentclass[12pt,a4paper]{article}
\usepackage{array}
\usepackage[demo]{graphicx}
\usepackage[export]{adjustbox}

\begin{document} \begin{tabular}{ >{$}c<{$} p{60mm} } A_n:\ y^2-x^{n+1}=0 & \includegraphics[width=\linewidth, valign=c]{images/An szing.pdf} \[10ex] D_n & \includegraphics[width=\linewidth, valign=c]{images/D_n szing.pdf} \end{tabular} \end{document}

enter image description here

Celdor
  • 9,058