0

I have a table, that works perfectly.
I just want the text to be centered vertically.
I do not want to use the array package, because I do not want to specify the column widths manually, I just want tabular to figure them out automatically.

I know I can specify

\begin{tabular}{c m{width} m{width} ......} but I don't want to manually enter the widths. I have a couple of these tables and I like the auto-width assigned by latex.

How do I do this in the following table?

\documentclass[a4paper,english,openright,twoside]{report}
\usepackage{array, ragged2e, booktabs} %yes, the array package is loaded
%NO, I do not want to specify the m{width} column types.

\begin{document}
\begingroup
\setlength{\tabcolsep}{4pt}
\begin{table}[H]
  \caption[Comparison of search algorithms]{Comparison of search algorithms //
  All timings are in milliseconds}

  \vspace{12pt}
  \begin{tabular}{c c r r r r r r r c}
    \textbf{Pattern} & \textbf{GoE?} & \textbf{CoMini-}  & \textbf{glucose} & \textbf{glucose-}& \textbf{lingeling} &\textbf{Maple} & \textbf{Grid-} &  \textbf{1\textsuperscript{st}\!\phantom{\textsuperscript{d}}} & \textbf{remarks} \\
     & & \textbf{SAT} & & \textbf{syrup} &  & & \textbf{Walker} & \textbf{vs 2\textsuperscript{nd} } &\\
    \midrule
    \includegraphics[scale=2]{GoE2}    & Yes &  150.82  & 154.35 & \textbf{126.72} & 237.50 & 1\,814.57 & 8.09 & 15.7$\times$ & \\ [1pt]
    \includegraphics[scale=2]{nonGoE2} & No  &   \textbf{52.06} &  66.77 & 56.61 & 78.25 & 2\,177.34 & 2.67 & 19.5$\times$ \\ [1pt]
    \includegraphics[scale=2]{GoE1a}   & Yes &  132.66  & 134.90 & \textbf{121.13} & 173.33 & 1\,637.11 & tbd  & tbd$\times$ \\ [1pt]
    \includegraphics[scale=2]{nonGoE3} & No  &   90.26 & \textbf{83.10}  & 122.05 & 179.93 & 1\,900.67 & 0.24 & 346.3$\times$ \\ [1pt]
    \includegraphics[scale=2]{block} & No  &   37.29  & \textbf{25.16}  & 36.03 & 45.46 & 30.22 & 0.49 & 51.3$\times$ \\ [1pt]
    \midrule
    Average & & 92.62 & 1\,511.98 & 92.86 & \textbf{92.51} & 142.89 & 2.87 & 32.2$\times$ \\
  \end{tabular}
  \label{tab:sat_vs_gridwalker}
\end{table}
\endgroup
\end{document}

Note that the images are 10x10 pixel png bitmaps.

  • The p{some width} column type is not defined by array, and you can perfectly use the r, lor c column types with array. – Bernard Feb 7 at 16:02
  • @Bernard, I know that, but those do not center vertically. m{} does, but that requires an explicit width. – Johan Feb 7 at 16:03
  • \makecell{picture} is the way to go, it is simple and works out of the box. \raisebox{-0.4\height}{picture} also works, but requires a little finetuning. On the plus side raisebox does not require an additional package. – Johan Feb 7 at 17:42
  • That's right, but makecell allows to define some vertical padding (the cellspace package also allows for vertical padding). – Bernard Feb 7 at 17:57
3

Here is a possibility with makecell. Note the table is too wide for a4paper, but maybe this is due to the [demo]option I had to use for \includegraphics.

\documentclass[a4paper,english,openright,twoside]{report}
\usepackage[hmargin = 0.5cm]{geometry}
\usepackage[demo]{graphicx}
\usepackage[export]{adjustbox}
\usepackage{array, ragged2e, booktabs, float, makecell, caption} %yes, the array package is loaded
%NO, I do not want to specify the m{width} column types.
\renewcommand{\theadfont}{\normalsize\bfseries}

\begin{document}

\begin{table}[H]
\setlength{\tabcolsep}{4pt}
  \caption[Comparison of search algorithms]{Comparison of search algorithms \\
  All timings are in milliseconds}
  \setcellgapes{3pt}\makegapedcells
  \begin{tabular}{c c*{7}{ r} c}
    \thead{Pattern} & \thead{GoE?} & \thead{CoMini-\\SAT} & \thead{glucose} & \thead{glucose-\\syrup}& \thead{lingeling} &\thead{Maple} & \thead{Grid-\\Walker} & \thead{1\textsuperscript{st} \phantom{\textsuperscript{d}}\\vs 2\textsuperscript{nd}} & \thead{remarks} \\
    \midrule
    \makecell{\includegraphics[scale=2]{GoE2}} & Yes & 150.82 & 154.35 & \textbf{126.72} & 237.50 & 1\,814.57 & 8.09 & 15.7$\times$ & \\
    \makecell{\includegraphics[scale=2]{nonGoE2}} & No & \textbf{52.06} & 66.77 & 56.61 & 78.25 & 2\,177.34 & 2.67 & 19.5$\times$ \\
    \makecell{\includegraphics[scale=2]{GoE1a}} & Yes & 132.66 & 134.90 & \textbf{121.13} & 173.33 & 1\,637.11 & tbd & tbd$\times$ \\
    \makecell{\includegraphics[scale=2]{nonGoE3}} & No & 90.26 & \textbf{83.10} & 122.05 & 179.93 & 1\,900.67 & 0.24 & 346.3$\times$ \\
    \makecell{\includegraphics[scale=2]{block}} & No & 37.29 & \textbf{25.16} & 36.03 & 45.46 & 30.22 & 0.49 & 51.3$\times$ \\
    \midrule%
    Average & & 92.62 & 1\,511.98 & 92.86 & \textbf{92.51} & 142.89 & 2.87 & 32.2$\times$ \\
  \end{tabular}
  \label{tab:sat_vs_gridwalker}
\end{table}

\end{document} 

enter image description here

3

Move the images down:

\documentclass[]{report}
\usepackage{graphicx}
\begin{document}
  \begin{tabular}{cc}
  \raisebox{-0.5\height}{\includegraphics[width=4cm]{example-image-duck}} & some text
  \end{tabular}

\end{document}

enter image description here

  • Nice! that would totally work, will try it out after diner. – Johan Feb 7 at 16:06
  • Yep, it works. The -0.5\height is a bit too much for my tiny pictures, so a bit of finetuning is needed. – Johan Feb 7 at 17:46
  • Try {\dimexpr 0.5\ht\strutbox-0.5\dp\strutbox-0.5\height}. That trys to align the center of a \strut instead of the baseline. – John Kormylo Feb 7 at 18:11

This site is temporarily in read only mode and not accepting new answers.

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