1

This is a follow-up question to "Alignment issues in a table".

Consider the following code:

\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}
\usepackage{siunitx}

\newcommand*\mc[1]{\multicolumn{3}{@{}c@{\mlrA}}{#1}}
\newcommand*\MC[1]{\multicolumn{3}{@{}c@{\mlrA}}{$\langle$#1$\rangle$}}
\newcommand*\Alignment[1]{%
  \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~2015--2016}
  \vspace{10ex}

  \renewcommand*{\arraystretch}{1.2}
  \begin{tabular}{
         S[table-format = 2] @{\mlrB}
         r @{\,--\,}
    *{5}{
         l @{\mlrA}
         l @{\mlrB}
         l @{\mlrB}
        }
         l
  }
   \toprule
    {Lektion}
    & \multicolumn{2}{@{}c@{\mlrA}}{Tidspunkt}
    & \multicolumn{3}{@{}c}{Mandag}
    & \multicolumn{3}{@{}c}{Tirsdag}
    & \mc{Onsdag}
    & \multicolumn{3}{@{}c}{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 & \MC{Fagdag}    \\[\mlrC]
     4 & 10:45 & 11:30 & 8.  & IDR  & hal/gym & 5.A & MAT  & 09  &     &      &    & 7.C & BIO & bio & \MC{Fagdag}    \\[\mlrC]
     5 & 11:30 & 12:00 & 5.A & FORD & 09      & 7.C & FORD & 22  & 5.A & FORD & 09 &     &     &     & \MC{Fagdag}    \\[\mlrC]
     6 & 12:40 & 13:25 & 7.C & GEO  & 22      & 5.A & HIS  & 09  & 7.C & MAT  & 22 &     &     &     & \MC{Fagdag}    \\[\mlrC]
     7 & 13:25 & 14:10 & 7.C & GEO  & 22      & 5.A & HIS  & 09  & 7.C & MAT  & 22 &     &     &     & \MC{Fagdag}    \\[\mlrC]
     8 & 14:25 & 15:10 & 7.C & MAT  & 22      &     &      &     &     &      &    & \mc{5.~årgang}  & \multicolumn{3}{@{}c@{\mlrA}}{($\langle$Fagdag$\rangle$)} \\[\mlrC]
     9 & 15:10 & 16:10 & \mc{7.~årgang}       & \mc{Fløj}        &     &      &    & \mc{5.~årgang}  &     &     &    \\[\mlrC]
    10 & 16:00 & 17:00 &     &      &         & \mc{Fløj}        &     &      &    &     &     &     &     &     &    \\
   \bottomrule
  \end{tabular}
\end{center}

\end{document}

output

How to I center <Fagdag> (and (<Fagdag>)) in the last column?

I guess the problem is do to a simple error by me but I can't figure out what it is.

Update

Is anyone creates an answer to my question (Sunilkumar KS has given the solution in an comment), I'll accept it and we can remove the question from the unanswered list.

  • Understand that those were coded in \MC command, which is suffixed with a horizontal skip (\mlrA) in \multicolumn. Please try with the following redefinition of \MC, where I removed \mlrA command. \newcommand*\MC[1]{\multicolumn{3}{@{}c@{}}{$\langle$#1$\rangle$}} – Sunilkumar KS Sep 22 '15 at 9:57
  • @SunilkumarKS Then the text is pushed too much to the right. – Svend Tveskæg Sep 22 '15 at 10:45
  • Now I noted that the columns are separated with horizontal spaces with \mlrA and \mlrB. I have slightly amended the code as below, please try this one. \newcommand*\MC[1]{\multicolumn{3}{@{}c@{\mlrB}}{$\langle$#1$\rangle$}} – Sunilkumar KS Sep 22 '15 at 11:54
1

enter image description here

your last four columns are

   l spaceA 
   l spaceB 
   l spaceB
   l \tabcolsep

So your \multicolumn{3} needs @{} on the left so no space is added to the left (the space B from the preceding column will be there) and then a nothing on the right to match the column specified space so you need

 \newcommand*\MC[1]{\multicolumn{3}{@{}c}{$\langle$#1$\rangle$}}

The whole document:

\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}
\usepackage{siunitx}

\newcommand*\mc[1]{\multicolumn{3}{@{}c@{\mlrA}}{#1}}
\newcommand*\MC[1]{\multicolumn{3}{@{}c}{$\langle$#1$\rangle$}}
\newcommand*\Alignment[1]{%
  \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~2015--2016}
  \vspace{10ex}

  \renewcommand*{\arraystretch}{1.2}
  \begin{tabular}{
         S[table-format = 2] @{\mlrB}
         r @{\,--\,}
    *{5}{
         l @{\mlrA}
         l @{\mlrB}
         l @{\mlrB}
        }
         l
  }
   \toprule
    {Lektion}
    & \multicolumn{2}{@{}c@{\mlrA}}{Tidspunkt}
    & \multicolumn{3}{@{}c}{Mandag}
    & \multicolumn{3}{@{}c}{Tirsdag}
    & \mc{Onsdag}
    & \multicolumn{3}{@{}c}{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 & \MC{Fagdag}    \\[\mlrC]
     4 & 10:45 & 11:30 & 8.  & IDR  & hal/gym & 5.A & MAT  & 09  &     &      &    & 7.C & BIO & bio & \MC{Fagdag}    \\[\mlrC]
     5 & 11:30 & 12:00 & 5.A & FORD & 09      & 7.C & FORD & 22  & 5.A & FORD & 09 &     &     &     & \MC{Fagdag}    \\[\mlrC]
     6 & 12:40 & 13:25 & 7.C & GEO  & 22      & 5.A & HIS  & 09  & 7.C & MAT  & 22 &     &     &     & \MC{Fagdag}    \\[\mlrC]
     7 & 13:25 & 14:10 & 7.C & GEO  & 22      & 5.A & HIS  & 09  & 7.C & MAT  & 22 &     &     &     & \MC{Fagdag}    \\[\mlrC]
     8 & 14:25 & 15:10 & 7.C & MAT  & 22      &     &      &     &     &      &    & \mc{5.~årgang}  & \multicolumn{3}{@{}c@{\mlrB}}{($\langle$Fagdag$\rangle$)} \\[\mlrC]
     9 & 15:10 & 16:10 & \mc{7.~årgang}       & \mc{Fløj}        &     &      &    & \mc{5.~årgang}  &     &     &    \\[\mlrC]
    10 & 16:00 & 17:00 &     &      &         & \mc{Fløj}        &     &      &    &     &     &     &     &     &    \\
   \bottomrule
  \end{tabular}
\end{center}

\end{document}

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.