2

I'm trying to put a \multicolumn within a \multirow environment in the following manner:

\documentclass{article}

\usepackage{multirow}
\usepackage{array}
\usepackage{mwe}

\begin{document}
    \begin{tabular}{|p{.03\textwidth}|p{.73\textwidth}|p{.03\textwidth}|p{.15\textwidth}|}
        Test1 & Test2 & Test3 &
        \multirow{1}{*}{\multicolumn{1}{m{\linewidth}}{\includegraphics[width=\linewidth]
        {example-image}}}
    \end{tabular}
\end{document}

For clarification, I have multiple rows in the table (6) and the multirow spans those 6 rows. The inner multicolumn is so that the image is centered within the multirow. However, I get the error:

Misplaced \Omit

Does anyone have any idea why this is happening? Thanks!

Update:

See Christian's answer for fixing the error. But latex was still having trouble centering the picture vertically when one of the rows was had multi line text. As a workaround, I increased the number of rows the multirow is spanning even though there are actually 6. This is admittedly an ugly hack and one I'm not particularly happy with, but it works for now. If anyone has any better solution, I'm open to suggestions.

Update 2:

Ok so update 2. See Christian's revised solution and comments for two possible ways to get around this problem. Thanks Christian for all the help!

  • 1
    You have to switch the \multirow and \multicolumn statements. \multicolumn outside, then \multirow inside. I suppose, the lines with 'Test1' etc. should be in multirow(s) as well. – user31729 Feb 19 '14 at 14:25
2

I suppose, this is what you meant.

\documentclass{article}

\usepackage{multirow}
\usepackage{array}
\usepackage{mwe}

\begin{document}
  \begin{tabular}{|p{.03\textwidth}|p{.73\textwidth}|p{.03\textwidth}|p{.15\textwidth}|}
          Test1 & Test2 & Test3 & 
    \multicolumn{1}{m{\linewidth}}{\multirow{6}{*}{\includegraphics[scale=0.1]{example-image}}% End of multirow
          }% End of multicolumn
      \\ % End of the first row 
       Line2  & & &\\
       Line3  & & & \\
       Line4  & & & \\
       Line5  & & & \\
       Line6  & & & \\
        \end{tabular}
\end{document}

Another version with vertical centered content, which uses the makecell package and the \multirowcell command, which allows for a vertical shift of the content in the tabular cell (First optional parameter of \multirowcell), which is set to -2pt by me since I have the impression, this aligns correctly, however, it has to be revised if the size/scaling of the image changes. It is a 'hack' as well, but perhaps it is better than adding extra rows.

 \documentclass{article}

    \usepackage{multirow,makecell}
    \usepackage{array}
    \usepackage{mwe}

    \begin{document}
        \begin{tabular}{|p{.1\textwidth}|p{.2\textwidth}|p{.1\textwidth}|p{.15  \textwidth}|}
          \hline
          Test1 & Test2 & Test3 & 
           \multirowcell{6}[-2pt]{\includegraphics[scale=0.1]{example-image}%
           }% End of multirowcell
          \\
           Line2  & & & \\
           Line3  & & & \\
           Line4  & & & \\
           Line5  & & & \\
           Line6  & & & \\
        \hline
        \end{tabular}

    \end{document}

I added the \hline in order to check to the alignment and reduced the width of columns. Please roll back as you desire.

Screenshot multirow cell

By the way, the \multirow command allows also a vertical shifting, but I have not tried that so far.

  • This fixes the error, but now I have the problem that latex centers the picture in only one row, whereas I want it to be centered across all six rows. Plus if I specify column borders, they are applied to only one row, whereas they should be applied to all six rows. Does that make sense? – K G Feb 19 '14 at 15:01
  • @KG: You have to change the 1 as an argument to \multirow to 6. Additionally, I added five 'dummy' lines. Sorry, I forgot that you wanted to have six rows in my answer initially. – user31729 Feb 19 '14 at 15:06
  • yes I am aware of that. I have already done that. Let me test your code and I'll get back to you. – K G Feb 19 '14 at 15:07
  • Ok I did a little bit more digging around and have figured out that the problem is when text in a row spans multiple lines. Latex seems to center the figure assuming single-line rows. The alignment is thrown off when one or more of the rows has multiline. Any solution for that? – K G Feb 19 '14 at 15:35
  • Not at the moment, sorry, for I am writing on a tablet and have no access to LaTeX at the moment. What about a parbox containing your figure, alignment can be done within? – user31729 Feb 19 '14 at 15:54

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.