0

In the first row the column containg A is not centering in the middle of the block only at the bottom and cant figure out why. Here is the latex stuff

\documentclass[a4paper,10pt]{article}

\usepackage{multirow}

\begin{document}

\begin{table}[H]
\label{table:LG_0^0}
\centering
\caption{Laguerre Gaussian $L_0^0$ Beam improvement}
\begin{tabular}{| m{0.5cm} | m{1.5cm} | m{1cm} | m{3cm} | m{3cm} | m{3cm} |}
\hline
A &
\multicolumn{3}{|c|}{\includegraphics[width=0.4\textwidth, height=0.3\textwidth]{D7_BH.png}} & \multicolumn{2}{|c|}{\includegraphics[width=0.4\textwidth, height=0.3\textwidth]{D7_IL.png}}\\
\hline
&Iterations & error value & Initial Zernike Hologram & Final Zernike Hologram & Final Laser\\
\hline
B & 8 & $1e^{-3}$ & \includegraphics[width=3cm, height=2.5cm]{D7_IH.png} & \includegraphics[width=3cm, height=2.5cm]{D7_FH.png} & \includegraphics[width=3cm, height=2.5cm]{D7_FL.png}\\
\hline
C & 2 & $1e^{-2}$ & \includegraphics[width=3cm, height=2.5cm]{D8_IH.png} & \includegraphics[width=3cm, height=2.5cm]{D8_FH.png} & \includegraphics[width=3cm, height=2.5cm]{D8_FL.png}\\
\hline
\end{tabular}
\end{table}

\end{document}

Here is the result screenshot1

5
  • Welcome to TSE. Please post a Minimal Working Example, instead of a code snippet. Commented Jan 12, 2023 at 8:14
  • Sorry about that should be fine now
    – WarLord
    Commented Jan 12, 2023 at 8:20
  • Please double-check that your MWE is indeed a minimal working example. It doesn't compile in its current form. Please also have in mind that we do not have your image files; Have a look at the images section of the answer to the linked MWE question of José.
    – nox
    Commented Jan 12, 2023 at 8:47
  • Welcome. // Watching your screenshot I wonder if you talk about an optical effect. I.e. when you draw an imaginary line left of the numbers on the y-axis, it seems to be centered. // It may be more evident and more pleasing to look at when you add a light-gray background for your drawings, i.e. making their bounding box or frame visible.
    – MS-SPO
    Commented Jan 12, 2023 at 9:01
  • Your posted code does not work at all [H] not defined , \includegraphics not defined. but also do not do [width=3cm, height=2.5cm] it will distort the image, just specify one or the other. Commented Jan 12, 2023 at 12:27

3 Answers 3

3

For a start, I consider it an insult to the people that are trying to help you, if you give them a document that isn't working. For example because it uses unknow images and not all required packages are included.

The problem with your setup is that the first row images are typeset in a c cell that doesn't vertically center its contents like the m{..} cells do. So these images have their baseline at the bottom and the A is aligned with it. So you have to make sure that the baseline of these images is in their vertical center. One way to do this is to use the adjustbox package with the export option and include valign=c in the \includegraphics.

\documentclass[a4paper,10pt]{article}

\usepackage{multirow}
\usepackage{array}
\usepackage{graphicx}
\usepackage[export]{adjustbox}

\begin{document}

\begin{table}
\label{table:LG_0^0}
\centering
\caption{Laguerre Gaussian $L_0^0$ Beam improvement}
\begin{tabular}{| m{0.5cm} | m{1.5cm} | m{1cm} | m{3cm} | m{3cm} | m{3cm} |}
\hline
A &
\multicolumn{3}{|c|}{\includegraphics[width=0.4\textwidth, height=0.3\textwidth,valign=c]{example-image}} & \multicolumn{2}{|c|}{\includegraphics[width=0.4\textwidth, height=0.3\textwidth,valign=c]{example-image}}\\
\hline
&Iterations & error value & Initial Zernike Hologram & Final Zernike Hologram & Final Laser\\
\hline
B & 8 & $1e^{-3}$ & \includegraphics[width=3cm, height=2.5cm]{example-image} & \includegraphics[width=3cm, height=2.5cm]{example-image} & \includegraphics[width=3cm, height=2.5cm]{example-image}\\
\hline
C & 2 & $1e^{-2}$ & \includegraphics[width=3cm, height=2.5cm]{example-image} & \includegraphics[width=3cm, height=2.5cm]{example-image} & \includegraphics[width=3cm, height=2.5cm]{example-image}\\
\hline
\end{tabular}
\end{table}

\end{document}

enter image description here

2

Slightly modified Pieter van Oostrum's answer (+1) with extra strut.

enter image description here

EDIT. @OP, please remove optional argument [draft] of graphicx package to get your images back. I don't have access to your files so the document had to be compiled this way.

The code:

\documentclass[a4paper,10pt]{article}
\usepackage{array}
\usepackage{multirow}
\usepackage{float}
\usepackage[draft]{graphicx}
\usepackage[export]{adjustbox}

\newcolumntype{L}[1]{p{#1}}
\newcommand\xlocstrut[1]{\rule[\dimexpr0.55ex-0.5\dimexpr#1]{0pt}{#1}}


\begin{document}

\begin{table}[H]
  \label{table:LG_0^0}
  \centering
  \caption{Laguerre Gaussian $L_0^0$ Beam improvement}
  \begin{tabular}{| L{0.5cm} | L{1.5cm} | L{1cm} | L{3cm} | L{3cm} | L{3cm} |}
    \hline
    A
    & \multicolumn{3}{c|}{%
      \xlocstrut{0.31\textwidth}
      \includegraphics[width=0.4\textwidth, height=0.3\textwidth, valign=c]{D7_BH.png}}
    & \multicolumn{2}{c|}{%
      \includegraphics[width=0.4\textwidth, height=0.3\textwidth, valign=c]{D7_IL.png}} \\
    \hline
    & Iterations & error value & Initial Zernike Hologram & Final Zernike Hologram & Final Laser \\
    \hline
    B & 8 & $1e^{-3}$
    & \xlocstrut{2.65cm}%
      \includegraphics[width=3cm, height=2.5cm, valign=c]{D7_IH.png}
                 & \includegraphics[width=3cm, height=2.5cm, valign=c]{D7_FH.png}
                               & \includegraphics[width=3cm, height=2.5cm, valign=c]{D7_FL.png} \\
    \hline
    C & 2 & $1e^{-2}$
    & \xlocstrut{2.65cm}%
      \includegraphics[width=3cm, height=2.5cm, valign=c]{D8_IH.png}
                 & \includegraphics[width=3cm, height=2.5cm, valign=c]{D8_FH.png}
                               & \includegraphics[width=3cm, height=2.5cm, valign=c]{D8_FL.png}\\
    \hline
  \end{tabular}
\end{table}

\end{document}
2

I set the horizontal and vertical directions to be centered, which is more beautiful.

\documentclass[a4paper,10pt]{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tabularray}
\usepackage[export]{adjustbox}
\begin{document}
\begin{table}
\centering
\caption{Laguerre Gaussian $L_0^0$ Beam improvement}
\label{table:LG_0^0}
\begin{tblr}
{
hlines,
vlines,
colspec    = {Q[c,m,0.5cm]Q[c,m,1.5cm]Q[c,m,1cm]Q[c,m,3cm]Q[c,m,3cm]Q[c,m,3cm]},
cell{1}{2} = {c=3}{},
cell{1}{5} = {c=2}{}
}
A & \includegraphics[width=0.4\textwidth,height=0.3\textwidth,valign=c]{example-image} &             &                                                                  & \includegraphics[width=0.4\textwidth,height=0.3\textwidth,valign=c]{example-image} &                                                                  \\
  & Iterations                                                                         & error value & Initial Zernike Hologram                                         & Final Zernike Hologram                                                             & Final Laser                                                      \\
B & 8                                                                                  & $1e^{-3}$   & \includegraphics[width=3cm,height=2.5cm,valign=c]{example-image} & \includegraphics[width=3cm,height=2.5cm,valign=c]{example-image}                   & \includegraphics[width=3cm,height=2.5cm,valign=c]{example-image} \\
C & 2                                                                                  & $1e^{-2}$   & \includegraphics[width=3cm,height=2.5cm,valign=c]{example-image} & \includegraphics[width=3cm,height=2.5cm,valign=c]{example-image}                   & \includegraphics[width=3cm,height=2.5cm,valign=c]{example-image} \\
\end{tblr}
\end{table}
\end{document}

enter image description here

You must log in to answer this question.

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