2

I have this MWE:

\documentclass[12pt,landscape,a4paper]{article}
\usepackage{multirow}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{longtable}
\usepackage[utf8]{inputenc}
\usepackage[english,czech]{babel}
\usepackage{hyphenat}
\usepackage{siunitx,booktabs}
\sisetup{output-decimal-marker = {,}}
\usepackage{ragged2e}
\newcommand*\fixalign[2][]{\begin{tabular}{@{}S[#1]@{}}#2\end{tabular}}
\begin{document}
\begin{longtable}{p{4cm}ccS[table-format=1.1]}
\multirow{2}{4cm}{\strut \Centering Název} &
\multicolumn{2}{c}{\Centering Premiéra}  &
\multirow{2}{0.8cm}{\Centering Min. doba}  \\
 &\Centering Svět & \Centering ČR &  \\

\Centering Kazatel Kalašnikov &  1.2. & 3.4. & 5.8\\

\Centering Musíme si promluvit o Kevinovi &
\multirow{2}{*}{1.6.} &
\multirow{2}{*}{5.4} &
\multirow{2}{*}{\fixalign[table-format=1.1]{2.8}}\\
\end{longtable}
\end{document}

That compiles into this:

enter image description here

I would like 5.8 and 2.8 to be aligned. I figure I would need to define colums to have certain width and only then use siunitx, but I am not sure how to do that. (My actual table is much larger and slightly more complicated.)

5
  • I found this question: tex.stackexchange.com/questions/12663/… but I am failing in adapting it to longtable environment.
    – sup
    Aug 7, 2015 at 20:14
  • I would just leave the S columns alone, and add space between columns instead.
    – daleif
    Aug 7, 2015 at 20:18
  • Adding space is not feasible, I am trying to fit as much info on one page (I am actually using tiny font size already).
    – sup
    Aug 7, 2015 at 20:23
  • Then reconsider. Cramming too much information into a small space will not help your readers. S columns are already the narrowest they can be (when configured correctly)
    – daleif
    Aug 7, 2015 at 20:37
  • Well, it is an appendix Iwith raw data that I do not expect anybody to really read, just skim, and I do not want it to run over twenty pages. Even though, on second reading, it might work, but how do I add space between columns?
    – sup
    Aug 8, 2015 at 1:08

2 Answers 2

1

As usual, multirow is not the answer; I removed the unnecessary packages, add them back if you really need them.

\documentclass[12pt,a4paper]{article}
% the following three should be first
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,czech]{babel}

\usepackage{makecell}
\usepackage{ragged2e}
\usepackage{longtable}
\usepackage{siunitx,booktabs}
\sisetup{output-decimal-marker = {,}}


\begin{document}

\begin{longtable}{
  >{\Centering}m{4cm}
  S[table-format=1.1]
  S[table-format=1.1]
  S[table-format=1.1]
}
Název & \multicolumn{2}{c}{Premiéra}  & {Min.} \\
      & {Svět} & {ČR}                 & {deba} \\

Kazatel Kalašnikov &  1.2 & 3.4 & 5.8\\

Musíme si promluvit o Kevinovi & 1.6 & 5.4 & 2.8 \\
\end{longtable}
\end{document}

enter image description here

4
  • Thanks, that seems much simpler, but I would like "název" to be in thmiddle of the first two rows (like in my example), not on the first row. Can that be accomplished?
    – sup
    Aug 8, 2015 at 1:05
  • Ok, I can put název where I want using multirow. However, if I wanted to have something like 22.8.2012 instead of 1,6 and have it line breaked between 22.8. and 2012, how would I go about it? Right now, I am using parbox with the appropriate width and manual linebreaks (`\\`), which seems suboptimal.
    – sup
    Aug 8, 2015 at 9:29
  • Hm, with enough hacks, I am able to print out what I want, so accepting. Even though I am sure you would be appalled if you saw my sourcode. BTW: I use microtype everywhere as it is said to improve things in general, lmodren as I prefer it (and without it, for some reason lmodern fonts are not used) but hyphenat was probably excessive, I am not sure why I still cary it in my standr preamble that I just copy over.
    – sup
    Aug 8, 2015 at 9:57
  • 1
    @sup I'm not saying those packages are not useful: they aren't necessary for the example. If I added them, future readers might think they are.
    – egreg
    Aug 8, 2015 at 17:38
0

A quick solution without \newcommands:

enter image description here

\documentclass[12pt,landscape,a4paper]{article}
\usepackage{multirow}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{longtable}
\usepackage[utf8]{inputenc}
\usepackage[english,czech]{babel}
\usepackage{hyphenat}
\usepackage{siunitx,booktabs}
\sisetup{output-decimal-marker = {,}}
\usepackage{ragged2e}

\begin{document}
\begin{longtable}{p{4cm}ccS[table-format=1.1]}
\multirow{2}{4cm}{\strut \Centering Název} &\multicolumn{2}{c}{\Centering Premiéra}  & \multirow{2}{0.8cm}{\Centering Min. doba}  \\
 &\Centering Svět & \Centering ČR &  \\
\Centering Kazatel Kalašnikov &  1.2 & 3.4 & \multirow{1}{*}{5.8}\\
\Centering Musíme si promluvit o Kevinovi & \multirow{2}{*}{1.6} & \multirow{2}{*}{5.4} & \multirow{2}{*}{2.8}\\
\end{longtable}
\end{document}
2
  • That does not take into account decimal marker (it should be a comma, not a dot, as per sisetup), can that be corrected please?
    – sup
    Aug 7, 2015 at 20:25
  • Also, no the header (Min. doba) is not aligned with the column (I would like the header to be at the center of the column's content).
    – sup
    Aug 7, 2015 at 20:26

You must log in to answer this question.

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