1

I want to have two row heading for my longtable and I am using this:

\documentclass[12pt,landscape,a4paper]{article}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{longtable}
\usepackage[utf8]{inputenc}
\usepackage[english,czech]{babel}
\usepackage{hyphenat}
\usepackage{booktabs}
\usepackage{geometry}
\usepackage{ragged2e}
\begin{document}
\begin{longtable}{cp{1.7cm}p{1.7cm}p{1.7cm}c}
\parbox{1.4cm}{blable\-bloblu} &
\multicolumn{3}{l}{
\begin{tabular}{@{}p{1.7cm}p{1.7cm}p{1.7cm}@{}}
\multicolumn{3}{c}{onetwothreefour}\\
one &   two  & three
\end{tabular}
}
& \parbox{0.7cm}{bla\-ble} \\
\hline
one & two & three & four & five
\endhead
\end{longtable}
\end{document}

It looks almost great, only the "one two three" row is vertically a bit too height and not alligned with "bloblu" and "ble" (see screenshot):enter image description hereAny idea how to put it lower? (Simpler solutions to make a two row aligned heading are welcome too.) (The solution to remove horizontal padding goes comes from here: How can the margins around a table set to 0pt?

Update: With @Heiko Oberdiek suggestions, I produced this document:

\documentclass[12pt,landscape,a4paper]{article}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{longtable}
\usepackage[utf8]{inputenc}
\usepackage[english,czech]{babel}
\usepackage{hyphenat}
\usepackage{booktabs}
\usepackage{geometry}
\usepackage{ragged2e}
\begin{document}
\begin{longtable}{p{1.4cm} p{0.7cm} p{0.7cm} p{0.7cm} p{0.7cm}c}
\strut Název \strut & 
\multicolumn{3}{l}{\begin{tabular}{@{}p{0.7cm}p{0.7cm}p{0.7cm}@{}}\multicolumn{3}{c}{Distribuce} \\ Svět &   ČR  & DVD \end{tabular}} &
\parbox{0.7cm}{\strut Pů\-vod \strut}   
\\
\end{longtable}
\normalsize
\end{document}

It looks like this ("Původ" is way to high):enter image description here This is my actual document produced by stripping down almost everything.

Result: without [-0.3pt] applied:enter image description here

With [-0.3pt] applied: enter image description here (I guess one needs to download the pictures and then look at them in succession to see the difference, but there is a difference. The last look is fully satisfactory, thanks!)

1

A solution using multirow, and booktabs, whose rule commands have some vertical padding (this padding can be changed with the \aboverulesep and belowrulesep lengths):

\documentclass[12pt,landscape,a4paper]{article}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{longtable, multirow}
\usepackage[utf8]{inputenc}
\usepackage[english,czech]{babel}
\usepackage{hyphenat}
\usepackage{booktabs}
\usepackage{geometry}
\usepackage{ragged2e}

\begin{document}

\begin{longtable}{p{1.4cm} p{0.7cm} p{0.7cm} p{0.7cm} p{0.7cm}}
  \toprule
  \multirow{2}{*}{ Název} & \multicolumn{3}{c}{Distribuce} &
  \multirow{2}{*}[1.25pt]{\parbox{0.7cm}{ Pů\-vod}} \\
    & Svět & ČR & DVD & \\
  \bottomrule
\end{longtable}
\vskip1cm

\begin{longtable}{cp{1.7cm}p{1.7cm}p{1.7cm}c}
  \multirow{2}{*}[1.2pt]{\parbox{1.4cm}{blable\-bloblu}} &
  \multicolumn{3}{c}{onetwothreefour}& \multirow{2}{*}[1.2pt]{\parbox{0.7cm}{bla\-ble}} \\
      & one & two & three & \\
  \midrule
  one & two & three & four & five
  \endhead
\end{longtable}

\normalsize
\end{document} 

enter image description here

  • The multirow and multicolumn approach works the best (but there is still one pixel different visible even in your image - I will just have to live by it, not that bug of a deal actually). Thanks! – sup Jun 26 '15 at 23:15
  • 1
    ??? In my pdfviewer, there's no difference (or if there is, it's less than 0.1pt, measured with the tool provided by SumatraPDF): I adjusted the vertical placement with the optional argument of \multirow. Anyway, it's easy to change the value – Bernard Jun 26 '15 at 23:38
  • Well, there is a small difference, using [-0.3pt] fixes it. Thanks for the option!I added screenshots to the answer. It is true it was only clearly visible when I magnified it to 400 %, but that is the point of Tex, that even such small differences affect the overall appearance of the document, no? – sup Jun 27 '15 at 9:03
1

Table rows automatically add struts, which is not done in \parbox. Thus adding \struts help here to get better alignments (with \arraystretch defined with its default 1):

\documentclass[12pt,landscape,a4paper]{article}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{longtable}
\usepackage[utf8]{inputenc}
\usepackage[english,czech]{babel}
\usepackage{hyphenat}
\usepackage{booktabs}
\usepackage{geometry}
\usepackage{ragged2e}
\begin{document}
\begin{longtable}{cp{1.7cm}p{1.7cm}p{1.7cm}c}
\parbox{1.4cm}{\strut blable\-bloblu\strut} &
\multicolumn{3}{l}{
\begin{tabular}{@{}p{1.7cm}p{1.7cm}p{1.7cm}@{}}
\multicolumn{3}{c}{onetwothreefour}\\
one &   two  & three
\end{tabular}
}
& \parbox{0.7cm}{\strut bla\-ble\strut} \\
\hline
one & two & three & four & five
\endhead
\end{longtable}
\end{document}

Result

Alternative version with inner tabulars instead of \parbox:

\begin{longtable}{cp{1.7cm}p{1.7cm}p{1.7cm}c}
  \begin{tabular}{@{}p{1.4cm}@{}}blable\-bloblu\end{tabular} &
\multicolumn{3}{l}{
\begin{tabular}{@{}p{1.7cm}p{1.7cm}p{1.7cm}@{}}
\multicolumn{3}{c}{onetwothreefour}\\
one &   two  & three
\end{tabular}
}
& \begin{tabular}{@{}p{.7cm}@{}}bla\-ble\end{tabular} \\
\hline
one & two & three & four & five
\endhead
\end{longtable}

Second MWE with inner tabulars:

\documentclass[12pt,landscape,a4paper]{article}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{longtable}
\usepackage[utf8]{inputenc}
\usepackage[english,czech]{babel}
\usepackage{hyphenat}
\usepackage{booktabs}
\usepackage{geometry}
\usepackage{ragged2e}
\begin{document}
\begin{longtable}{p{1.4cm} p{0.7cm} p{0.7cm} p{0.7cm} p{0.7cm}c}
Název &
\multicolumn{3}{l}{\begin{tabular}{@{}p{0.7cm}p{0.7cm}p{0.7cm}@{}}\multicolumn{
\\ Svět &   ČR  & DVD \end{tabular}} &
\begin{tabular}{@{}p{0.7cm}@{}}Pů\-vod\end{tabular}
\\
\end{longtable}
\end{document}

Result 2nd MWE with tabular

  • Thanks. This is weird. \strut fixes my MWE, but when I try to apply it to my actual document, it does not work. I stripped it down and came up with another MWE (please see the original question at the bottom) that misbehabes even with \strut - using tabular seems to have the same effect. Any idea why it does not work on the second MWE? – sup Jun 26 '15 at 21:21

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.