29
\begin{table}[!h]
  \centering
  \caption{Titel}
  \resizebox{.95\columnwidth}{!}{%
    \begin{tabular}{p{4.5cm}p{10cm}p{3.5cm}}
        \hline
        Name & \multicolumn{2}{p{\textwidth-3\tabcolsep-\widthof{test}-2\fboxrule}}
            {long_title which goes over two coloums}\\
        \hline
        Explanation & \multicolumn{2}{p{\textwidth-3\tabcolsep-\widthof{test}-2\fboxrule}}
            {Explanation which goes over two coloums}\\
        \hline
    \multirow{3}{*}{Targets} 
                    & Target 1 is long text with two lines & not reached\\
        \cline{2-3}
        & Target 2 & reached\\
        \cline{2-3}
        & Target 3 & reached\\
        \hline

    \end{tabular}%
    }
  \label{tab:test}%
\end{table}% 

I hope this photo helps to understand my problem:

enter image description here

I would like to align the text "Targets" on the top of the cell, like the second table. I'm sure this must be simple to do, but I can't seem to put my finger on it.

4
  • 1
    Do i have to use something else than the "*" ?
    – newbie_Tex
    Sep 25, 2012 at 13:18
  • 1
    This seems like the opposite of your problem, it may help you: stackoverflow.com/questions/1910478/… Sep 25, 2012 at 13:23
  • 1
    What if the reason of using multirow is you want top alignment, but also splitting over multiple rows. Then you can't just leave multirow out of play, because then you get a white line in following columns next to the multiple lined text. (Hope I am making myself a bit clear here)
    – user23624
    Dec 24, 2012 at 11:40
  • 1
    It's super easy with a recent version of the multirow package. See MoonKnight's for the correct answer.
    – normanius
    Feb 14, 2019 at 14:29

9 Answers 9

21

Using \multirow (from the multirow package) pushes the contents down to the middle of 3 rows. Instead just drop the use of \multirow to have the cell top-aligned:

enter image description here

\documentclass[12pt]{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
%\usepackage{multirow}% http://ctan.org/pkg/multirow
\usepackage{calc}% http://ctan.org/pkg/calc
\begin{document}
\begin{table}[!ht]
  \centering
  \caption{Titel}
  \resizebox{.95\columnwidth}{!}{%
    \begin{tabular}{p{4.5cm}p{10cm}p{3.5cm}}
        \hline
        Name & \multicolumn{2}{p{\textwidth-3\tabcolsep-\widthof{test}-2\fboxrule}}
            {long title which goes over two columns}\\
        \hline
        Explanation & \multicolumn{2}{p{\textwidth-3\tabcolsep-\widthof{test}-2\fboxrule}}
            {Explanation which goes over two columns}\\
        \hline
        Targets % Don't use \multirow{4}{*}{Targets} here
            & Target 1 is long text with two lines exactly like this spans two lines & not reached\\
        \cline{2-3}
        & Target 2 & reached\\
        \cline{2-3}
        & Target 3 & reached\\
        \hline
    \end{tabular}%
    }
  \label{tab:test}%
\end{table}
\end{document} 
4
  • 22
    The answer doesn't answer how to align to top in \multirow.
    – chejnik
    Apr 8, 2014 at 13:55
  • 3
    @chejnik: In this instance you can use \multirow{3}{*}[\normalbaselineskip]{Targets}, but the suggestion to do without it is far superior than fiddling with raising/lowering content in one column to match the other.
    – Werner
    Apr 9, 2014 at 5:04
  • 2
    I see, thank you. I wanted to point out that it is only coincidence that the first column is smaller than the second one. In my case I had first column (\multirow column) much larger and need to align it on top.
    – chejnik
    Apr 9, 2014 at 5:48
  • 2
    @chejnik: True. There are other methods that one can use, including nesting a tabular inside a tabular and using the vertical alignment "anchor" point, or even using a \parbox. In this specific instance, it was easier to do it without \multirow.
    – Werner
    Apr 9, 2014 at 14:12
37

This is easily handled with the newly updated multirow command. There is an option that specifies vertical text alignment; put [t] for top alignment.

In your example you would write:

\multirow[t]{3}{*}{Targets} & Target 1 is long text with two lines & not reached\\

Here is the code that should yield the desired output:

\begin{table}[!h]
  \centering
  \caption{Title}
    \begin{tabular}{lll}
        \hline
        Name & \multicolumn{2}{l}{long title which goes over two columns}\\
        \hline
        Explanation & \multicolumn{2}{l}{Explanation which goes over two columns}\\
        \hline    
    \multirow[t]{3}{*}{Targets} & Target 1 is long text with two lines & not reached\\
        \cline{2-3}
        & Target 2 & reached\\
        \cline{2-3}
        & Target 3 & reached\\
        \hline
    \end{tabular}%
  \label{tab:test}%
\end{table}

enter image description here

P.S: Don't forget to add the multirow package.

2
  • 6
    This should be the accepted answer.
    – user156344
    Mar 26, 2019 at 4:34
  • When I use this when the multirow text (aka "Targets") has a larger font size than the rest of the table, it spills upwards, is there a way to fix that?
    – Jeffmagma
    Jan 21, 2022 at 20:50
6

Instead of specifying the widths of the columns explicitly use the l specifier (which may require the array package). An example of its usage would be the following

\begin{center}
     \begin{tabular}{ | l | l | l | p{5cm} |}
     \hline
     Day & Min Temp & Max Temp & Summary \\ \hline
     Monday & 11C & 22C & A clear day with lots of sunshine.  
     However, the strong breeze will bring down the temperatures. \\ \hline
     Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
     across most of Scotland and Northern Ireland,
     but rain reaching the far northwest. \\ \hline
     Wednesday & 10C & 21C & Rain will still linger for the morning.
     Conditions will improve by early afternoon and continue
     throughout the evening. \\
     \hline
     \end{tabular}
\end{center}

this will provide an output like this

Example

Note the top alignment of all columns.

I hope this helps.

2
  • thank you for the try, but there is a reason why i have the widths
    – newbie_Tex
    Sep 25, 2012 at 13:38
  • 1
    Since you did not change the example at all, it will be nice if you mention in your answer that you got the example from wikibooks or some other place.
    – mythealias
    Dec 25, 2012 at 11:19
3

I have been troubled with this alignment as well. So, I end up with combination with fix-up parameter and filling vertical space I use

\multirow{2}{*}[2em]{\vfil Target}

The \vfill will move the first character start on second row. And the 2em move the base line to first row. You can adjust 2em if too up/down.

3

I have faced the same problem, since I have nested tables. I see someone else has beaten me to it, so I reiterate their answer verbatim –buth with emphasis on tables added– since none of the other solutions on this page work well when positioning tables within a multirow.

\multirow{2}{*}[2em]{\vfil <insert table here>}
1
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. This should be a comment to the answer by user2670906. Dec 2, 2015 at 12:24
2

this is an inelegant hack, and not automatic, but if you force the one-line "Targets" to occupy two lines, it should force that text to the top line:

\multirow{3}{*}{Targets\\ \phantom{.}} 
                & Target 1 is long text with two lines & not reached\\
    \cline{2-3}
2

I will give a better solution with LaTeX3 package tabularray. For multirow cells, there are h and f option for top and bottom alignment, respectively.

\documentclass{article}

\usepackage{caption}
\usepackage{tabularray}

\begin{document}

\begin{table}[!h]
  \centering
  \caption{Title}
    \begin{tblr}{colspec={lll},hlines}
        Name & \SetCell[c=2]{l} long title which goes over two columns & \\
        Explanation & \SetCell[c=2]{l} Explanation which goes over two columns & \\ 
        \SetCell[r=3]{h} Targets & Target 1 is long text with two lines & not reached \\
            & Target 2 & reached \\
            & Target 3 & reached \\
    \end{tblr}%
  \label{tab:test}%
\end{table}

\end{document}

enter image description here

0

Here's another hack:

\multirow{2}{*}{Target ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
% enough spaces to push Target to top
1
  • This seems to defeat the purpose; you're using a \multirow only to push the content up.
    – Werner
    Jun 30, 2016 at 18:12
0

Simply make 1 row: \multirow{1}{*}{multilinetext}

enter image description here

\begin{tabular}{cll}
\toprule
\multirow{4}{*}{\begin{tabular}{r}A\\B\end{tabular}}
& foo  & Lorem ipsum dolor sit    \\
& bar  & Maecenas sed purus       \\
& baz  & Nullam luctus id tellus  \\
& qux  & Aenean consequat commodo \\
\bottomrule
\end{tabular}
~~~
\begin{tabular}{cll}
\toprule
\multirow{1}{*}{\begin{tabular}{r}A\\B\end{tabular}}
& foo  & Lorem ipsum dolor sit    \\
& bar  & Maecenas sed purus       \\
& baz  & Nullam luctus id tellus  \\
& qux  & Aenean consequat commodo \\
\bottomrule
\end{tabular}

You must log in to answer this question.

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