1

I'm trying to create a table in LaTeX which contains a multirow as height as the rest of the table. This table appears lots of times in my document. The problem is that the second row can contain different numbers of linebreaks. But the multirow package takes in advance the number of rows instead of the total number of lines. Normally each time I use this table I have to count the real number of lines and edit the number into the multirow options.

Now I'm looking for a way to count the lines and adjust the multirow automatically. Maybe a counter could be helpful? I've tried that possibility with the tabline counter and this works quite well (after compiling the second time). A similar option taking in advance all lines inside the table would be great. On Google I've found the lineno package with the option edtable. This could probably help but I don't know how to use it for my problem. Does anyone have an idea to solve this?

\documentclass[a4paper,pagesize]{scrartcl} 
\usepackage{tabularx}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{hhline}
\usepackage{array} 
\usepackage[edtable]{lineno} %% Could be helpful?
\newcounter{tabline}
\newcolumntype{n}{>{\refstepcounter{tabline}\thetabline\enspace}l} 

\begin{document}
\begin{table}[ht] \centering
        \begin{tabular}{| n | >{\centering\arraybackslash}p{.4\textwidth} | >    {\centering\arraybackslash}p{.4\textwidth} |}
                \hline
                TEST & TEST & \multirow{\ref{FOO}}{*}    {\includegraphics[width=.4\textwidth]{example-image-golden}} \\ \hhline{--~|}
                TEST & TEST & \\ \hhline{--~|}
                TEST & TEST \linebreak HERE IS A LINEBREAK & \\ \hhline{--~|}
                TEST & TEST & \\ \hhline{--~|}
                TEST & TEST & \\ \hhline{--~|}
                TEST & TEST \linebreak HERE IS ONE TOO & \\ \hhline{--~|}
                TEST & TEST \linebreak AND ANOTHER ONE & \\ \hhline{--~|}
                TEST & TEST & \\ \hhline{--~|}
                TEST\label{FOO} & TEST &  \\ \hline
        \end{tabular}   
\end{table}
The table contains~\ref{FOO} rows. \\
\end{document}
1
  • Nothing says all rows have to be the same size, or even multiples of \bigstrut. What you need is to measure the height of the multirow field (dimen). – John Kormylo Sep 5 '15 at 14:25
0

First, it is generally safer to use \getrefnumber from the refcount or hyperref packages.

To center something in a multirow field involves playing with the fixup parameter (which behaves in mysterious ways). It is far easier to use a \raisebox to fill the entire space and center the image inside. In either case, you will need to know the height of the multirow field. This can be done using \tikzmarks.

\documentclass[a4paper,pagesize]{scrartcl} 
\usepackage{tabularx}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{hhline}
\usepackage{array} 
\usepackage[edtable]{lineno} %% Could be helpful?
\usepackage{refcount}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\newcounter{tabline}
\newcolumntype{n}{>{\refstepcounter{tabline}\thetabline\enspace}l} 
\newlength{\tabsize}

\begin{document}
\begin{table}[ht]
\begin{tikzpicture}[remember picture,overlay]
  \coordinate (top) at (pic cs:top);% possibly redundant
  \coordinate (bottom) at (pic cs:bottom);
  \pgfextracty{\global\tabsize}{\pgfpointdiff{\pgfpointanchor{bottom}{center}}{\pgfpointanchor{top}{center}}}%
\end{tikzpicture}
\addtolength{\tabsize}{0.6\baselineskip}% tweak centering
\centering
        \begin{tabular}{| n | >{\centering\arraybackslash}p{.4\textwidth} | >    {\centering\arraybackslash}p{.4\textwidth} |}
                \hline
                TEST & TEST & \tikzmark{top}\multirow{\getrefnumber{FOO}}{*}{\raisebox{-0.5\height}[0.5\tabsize][0.5\tabsize]% center image in field
                  {\includegraphics[width=.4\textwidth]{example-image-golden}}} \\ \hhline{--~|}
                TEST & TEST & \\ \hhline{--~|}
                TEST & TEST \linebreak HERE IS A LINEBREAK & \\ \hhline{--~|}
                TEST & TEST & \\ \hhline{--~|}
                TEST & TEST & \\ \hhline{--~|}
                TEST & TEST \linebreak HERE IS ONE TOO & \\ \hhline{--~|}
                TEST & TEST \linebreak AND ANOTHER ONE & \\ \hhline{--~|}
                TEST & TEST & \\ \hhline{--~|}
                TEST\label{FOO} & TEST & \tikzmark{bottom} \\ \hline
        \end{tabular}   
\end{table}
The table contains~\ref{FOO} rows. \\
\end{document}

multirow image

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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