2

Consider the following example:

\documentclass[
  a4paper,
  12pt,
  landscape,
  danish
]{article}


\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[
  hmargin = 2.4cm,
  vmargin = 3cm
]{geometry}
\usepackage{fancyhdr}
\usepackage{booktabs}


\newcommand*\mc[1]{\multicolumn{3}{c}{#1}}
\newcommand*\Alignment[1]{% Justering ved `--'.
  \multicolumn{1}{r@{}}{\llap{\makebox[\widthof{--}][c]{#1}}}%
}

\def\mlrA{\hskip 2.5em}
\def\mlrB{\hskip 0.8em}
\def\mlrC{3ex}

\pagestyle{fancy}
\renewcommand*\headrulewidth{0pt}
\setlength\headheight{14.5pt}
\lhead{}
\rhead{}
\cfoot{}


\begin{document}

\begin{center}
  \textbf{\Huge Skema for skoleåret 2015--2016}
\end{center}
\vspace{5ex}

\begin{table}[htbp]
\centering
  \begin{tabular}{
    c @{\mlrB}
    r @{\,--\,}
    l @{\mlrA}
    l @{\mlrB}
    l @{\mlrB}
    l @{\mlrA}
    l @{\mlrB}
    l @{\mlrB}
    l @{\mlrA}
    l @{\mlrB}
    l @{\mlrB}
    l @{\mlrA}
    l @{\mlrB}
    l @{\mlrB}
    l @{\mlrA}
    l @{\mlrB}
    l @{\mlrB}
    l
  }
   \toprule
    Lektion & \multicolumn{2}{l}{Tidspunkt} & \mc{Mandag}{\mlrA}   & \mc{Tirsdag}{\mlrA} & \mc{Onsdag}{\mlrA} & \mc{Torsdag}{\mlrA} & \mc{Fredag}{\mlrA} \\
   \midrule
    1       &  8:10 &  8:55                 &     &      &         & 7.C & F/K  & fys    & 5.A & MAT  & 09    &     &     &         & 7.C & MAT & 22     \\[\mlrC]
    2       &  8:55 &  9:40                 &     &      &         & 7.C & F/K  & fys    & 5.A & N/T  & 09    &     &     &         & 7.C & STU & 22     \\[\mlrC]
    3       & 10:00 & 10:45                 & 8.  & IDR  & hal/gym & 5.A & MAT  & 09     & 7.C & STU  & 22    & 7.C & BIO & bio     &     &     &        \\[\mlrC]
    4       & 10:45 & 11:30                 & 8.  & IDR  & hal/gym & 5.A & MAT  & 09     &     &      &       & 7.C & BIO & bio     &     &     &        \\[\mlrC]
    5       & 11:30 & 12:00                 & 5.A & FORD & 09      & 7.C & FORD & 22     & 5.A & FORD & 09    &     &     &         &     &     &        \\[\mlrC]
    6       & 12:40 & 13:25                 & 7.C & GEO  & 22      & 5.A & HIS  & 09     & 7.C & MAT  & 22    &     &     &         &     &     &        \\[\mlrC]
    7       & 13:25 & 14:10                 & 7.C & GEO  & 22      & 5.A & HIS  & 09     & 7.C & MAT  & 22    &     &     &         &     &     &        \\[\mlrC]
    8       & 14:25 & 15:10                 & 7.C & MAT  & 22      & \mc{TEAM}{\mlrA}    &     &      &       &     &     &         &     &     &        \\
   \bottomrule
  \end{tabular}
\end{table}

\end{document}

output

Here are the two things I have problems with:

  • Is Tidspunkt exactly centered above the time intervals? (I'm not sure.)

  • How do I center Fredag above the last three columns and not just the first two of the last three?

P.S. If anyone has a "better" way of typing the table, feel free to supply your suggestion(s).

Update

Using Heiko Oberdiek's answer and simplifying the code marginally, here is what I ended up with:

\documentclass[
  a4paper,
  12pt,
  landscape,
  danish
]{article}



\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[
  hmargin = 2.4cm,
  vmargin = 3cm
]{geometry}
\usepackage{fancyhdr}
\usepackage{booktabs}



\newcommand*\mc[1]{\multicolumn{3}{@{}c@{\mlrA}}{#1}}
\newcommand*\Alignment[1]{% adjustment at `--'
  \multicolumn{1}{r@{}}{\llap{\makebox[\widthof{--}][c]{#1}}}%
}

\def\mlrA{\hskip 2.5em}
\def\mlrB{\hskip 0.8em}
\def\mlrC{3ex}

\pagestyle{fancy}
\renewcommand*\headrulewidth{0pt}
\setlength\headheight{14.5pt}
\lhead{}
\rhead{}
\cfoot{}



\begin{document}

\begin{center}
  \textbf{\Huge Skema for skoleåret~2015--2016}
  \vspace{10ex}

  \renewcommand*\arraystretch{1.2}
  \begin{tabular}{
         c @{\mlrB}
         r @{\,--\,}
    *{5}{
         l @{\mlrA}
         l @{\mlrB}
         l @{\mlrB}
        }
         l
  }
   \toprule
    Lektion
    & \multicolumn{2}{@{}c@{\mlrA}}{Tidspunkt}
    & \mc{Mandag}
    & \mc{Tirsdag}
    & \mc{Onsdag}
    & \mc{Torsdag}
    & \multicolumn{3}{@{}c}{Fredag} \\
   \midrule
    1 &  8:10 &  8:55 &     &      &         & 7.C & F/K  & fys & 5.A & MAT  & 09 &     &     &     & 7.C & MAT & 22 \\[\mlrC]
    2 &  8:55 &  9:40 &     &      &         & 7.C & F/K  & fys & 5.A & N/T  & 09 &     &     &     & 7.C & STU & 22 \\[\mlrC]
    3 & 10:00 & 10:45 & 8.  & IDR  & hal/gym & 5.A & MAT  & 09  & 7.C & STU  & 22 & 7.C & BIO & bio &     &     &    \\[\mlrC]
    4 & 10:45 & 11:30 & 8.  & IDR  & hal/gym & 5.A & MAT  & 09  &     &      &    & 7.C & BIO & bio &     &     &    \\[\mlrC]
    5 & 11:30 & 12:00 & 5.A & FORD & 09      & 7.C & FORD & 22  & 5.A & FORD & 09 &     &     &     &     &     &    \\[\mlrC]
    6 & 12:40 & 13:25 & 7.C & GEO  & 22      & 5.A & HIS  & 09  & 7.C & MAT  & 22 &     &     &     &     &     &    \\[\mlrC]
    7 & 13:25 & 14:10 & 7.C & GEO  & 22      & 5.A & HIS  & 09  & 7.C & MAT  & 22 &     &     &     &     &     &    \\[\mlrC]
    8 & 14:25 & 15:10 & 7.C & MAT  & 22      & \mc{TEAM}        &     &      &    &     &     &     &     &     &    \\
   \bottomrule
  \end{tabular}
\end{center}

\end{document}
  • For 2), use \mc{Fredag}{}. For 1) I'd say, "yes". – Gonzalo Medina Aug 17 '15 at 18:43
  • Why don't you use a single (centred) column for the time intervals? – Bernard Aug 17 '15 at 19:16
  • @Bernard If, for example, the third time interval was 9:55--10:45 this wouldn't be aligned properly with the other times. – Svend Tveskæg Aug 17 '15 at 19:29
  • 1
    Well, you can add an hphantom{0} before the 9. – Bernard Aug 17 '15 at 19:49
4

The normal \tabcolsep is replaced between most columns by \@{...}. This is added to the right of the column and needs to be repeated in \multicolumn. Thus, the definition for \mc should be:

\newcommand*\mc[1]{\multicolumn{3}{@{}c@{\mlrA}}{#1}}

And \mc is used with one argument only.

The last column ends with the normal \tabcolsep and \mc cannot be used, insted a normal \multicolumn will do:

\multicolumn{3}{@{}c}{Fredag}

And the centered title for columns 2 and 3:

\multicolumn{2}{@{}c@{\mlrA}}{Tidspunkt}

Now, the column titles should be centered correctly, see the following example. The example also reduces \mlrC, the line spaces in the table body and increased \arraystretch to make the overall line spacing a little smoother.

\documentclass[
  a4paper,
  12pt,
  landscape,
  danish
]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[
  hmargin = 2.4cm,
  vmargin = 3cm
]{geometry}
\usepackage{fancyhdr}
\usepackage{booktabs}

\newcommand*\mc[1]{\multicolumn{3}{@{}c@{\mlrA}}{#1}}
\newcommand*\Alignment[1]{% adjustment at `--'
  \multicolumn{1}{r@{}}{\llap{\makebox[\widthof{--}][c]{#1}}}%
}

\def\mlrA{\hskip 2.5em}
\def\mlrB{\hskip 0.8em}
\def\mlrC{1.5ex}

\pagestyle{fancy}
\renewcommand*\headrulewidth{0pt}
\setlength\headheight{14.5pt}
\lhead{}
\rhead{}
\cfoot{}

\begin{document}
\begin{center}
  \textbf{\Huge Skema for skoleåret 2015--2016}

  \vspace{5ex}

  \renewcommand*{\arraystretch}{1.3}
  \begin{tabular}{
    c @{\mlrB}
    r @{\,--\,}
    l @{\mlrA}
    l @{\mlrB}
    l @{\mlrB}
    l @{\mlrA}
    l @{\mlrB}
    l @{\mlrB}
    l @{\mlrA}
    l @{\mlrB}
    l @{\mlrB}
    l @{\mlrA}
    l @{\mlrB}
    l @{\mlrB}
    l @{\mlrA}
    l @{\mlrB}
    l @{\mlrB}
    l
  }
   \toprule
    Lektion
    & \multicolumn{2}{@{}c@{\mlrA}}{Tidspunkt}
    & \mc{Mandag}
    & \mc{Tirsdag}
    & \mc{Onsdag}
    & \mc{Torsdag}
    & \multicolumn{3}{@{}c}{Fredag} \\
   \midrule
    1  &  8:10 &  8:55  &     &      &         & 7.C & F/K  & fys  & 5.A & MAT  & 09  &     &     &      & 7.C & MAT & 22 \\[\mlrC]
    2  &  8:55 &  9:40  &     &      &         & 7.C & F/K  & fys  & 5.A & N/T  & 09  &     &     &      & 7.C & STU & 22 \\[\mlrC]
    3  & 10:00 & 10:45  & 8.  & IDR  & hal/gym & 5.A & MAT  & 09   & 7.C & STU  & 22  & 7.C & BIO & bio  &     &     &    \\[\mlrC]
    4  & 10:45 & 11:30  & 8.  & IDR  & hal/gym & 5.A & MAT  & 09   &     &      &     & 7.C & BIO & bio  &     &     &    \\[\mlrC]
    5  & 11:30 & 12:00  & 5.A & FORD & 09      & 7.C & FORD & 22   & 5.A & FORD & 09  &     &     &      &     &     &    \\[\mlrC]
    6  & 12:40 & 13:25  & 7.C & GEO  & 22      & 5.A & HIS  & 09   & 7.C & MAT  & 22  &     &     &      &     &     &    \\[\mlrC]
    7  & 13:25 & 14:10  & 7.C & GEO  & 22      & 5.A & HIS  & 09   & 7.C & MAT  & 22  &     &     &      &     &     &    \\[\mlrC]
    8  & 14:25 & 15:10  & 7.C & MAT  & 22      & \mc{TEAM}         &     &      &     &     &     &      &     &     &    \\
   \bottomrule
  \end{tabular}
\end{center}
\end{document}

Result

Since the table title belongs to the table, the table environment is removed and the table is put into the center environment with the table title. Alternatively, \centering could be used, when additional vertical spaces of the center environment is not needed/wanted.

  • The tabular should be in the same center environment as the title. – egreg Aug 17 '15 at 19:19
  • The TEAM entry is not aligned properly but I've fixed that myself. – Svend Tveskæg Aug 17 '15 at 19:30
  • @egreg Thanks, the updated answer provides a cleanup for the centering stuff. – Heiko Oberdiek Aug 17 '15 at 19:32
  • @SvendTveskæg Thanks, I noticed while cleaning up the centering stuff and the updated answer also fixes this. – Heiko Oberdiek Aug 17 '15 at 19:33

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.