改进难看的表格

改进难看的表格

考虑以下“恐怖表”,其中的代码既不简洁,又极其丑陋:

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

\usepackage{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[
  hmargin = 2.0cm,
  vmargin = 2.6cm
]{geometry}
\usepackage{booktabs,multirow}
\usepackage{microtype}

\def\mlrA{\hskip 2.5em}
\def\mlrB{\hskip 0.8em}
\def\mlrC{2ex}
\def\pause{5ex}

\newcommand*\mc[1]{\multicolumn{3}{@{}c@{\mlrA}}{\mlrB#1}}
\newcommand*\mr[1]{\multirow{2}{*}{#1}}
\newcommand*\mcr[8]{\multicolumn{#1}{c}{\multirow{#2}{*}{\hspace*{#3em}#4\hspace*{#5em}#6\hspace*{#7em}#8}}}
\newcommand*\intet{\mcr{2}{1}{0}{}{0}{}{0}{}}
\newcommand*\Alignment[1]{% Justering ved `--'.
  \multicolumn{1}{r@{}}{\llap{\makebox[\widthof{--}][c]{#1}}}}
\newcommand*\moeder{\mc{Møder}}

\DisableLigatures[f]{encoding = T1}
\pagestyle{empty}


\begin{document}

\begin{center}
  \bfseries
  \Huge
  Skema for skoleåret~2021/2022
\end{center}
\vspace*{3.28ex}

\begin{center}
 \renewcommand*{\arraystretch}{1.2}
  \begin{tabular}{
         c @{\mlrB}
         r @{\,--\,}
    *{5}{
         l @{\mlrA}
         l @{\mlrB}
         l @{\mlrB}
        }
         l
  }
   \toprule
    {Lektion}
    & \multicolumn{2}{@{}c@{\mlrA}}{Tidsrum}
    & \mc{Mandag}
    & \mc{Tirsdag}
    & \mc{Onsdag}
    & \mc{Torsdag}
    & \mc{Fredag} \\
   \midrule
     1 &  7:55 &  8:40 & 8.Y & F/K & C-29 &     &     &      & 9.C & F/K & C-29 & 7.B & F/K & C-29   & 8.X & MAT & C-11 \\[\mlrC]
     2 &  8:40 &  9:25 & 8.Y & F/K & C-29 & 8.X & MAT & C-11 & 9.C & F/K & C-29 & 7.B & F/K & C-29   &     &     &      \\[\mlrC]
       &  9:25 &  9:40 & \mc{Pause}       & \mc{Pause}       & \mc{Pause}       & \mc{Pause}         & \mc{Pause}       \\[\mlrC]
     3 &  9:40 & 10:25 & 8.X & MAT & C-11 &     &     &      &     &     &      & 9.A & F/K & C-29   & 9.C & F/K & C-29 \\[\mlrC]
     4 & \multicolumn{2}{c}{\multirow{2}{*}{\hspace*{-2.5em}10:25\,--\,11:10}}
       & \mcr{3}{1}{-2.5}{7.B}{0.9}{STU}{1.0}{C-16}
       & \mcr{3}{2}{-2.5}{7.A}{0.85}{STJ}{1.3}{C-14}
       & \mcr{3}{2}{-2.5}{7.A}{0.85}{STJ}{0.9}{C-14}
       & \mcr{3}{2}{-2.5}{9.A}{0.85}{STJ}{0.8}{C-29}
       & \mcr{3}{2}{-0.5}{9.C}{0.80}{STJ}{1.2}{C-29} \\
       & \intet        & 8.X & MAT & C-11 &     &     &      &     &     &      &     &     &        &     &     &      \\[\mlrC]
       & 11:10 & 11:35 & \mc{Pause}       & \mc{Pause}       & \mc{Pause}       & \mc{Pause}         & \mc{Pause}       \\
       & 11:35 & 11:50 & \mc{Spisepause}  & \mc{Spisepause}  & \mc{Spisepause}  & \mc{Spisepause}    & \mc{Spisepause}  \\[\mlrC]
     5 & 11:50 & 12:35 &     &     &      &     &     &      &     &     &      &     &     &        &     &     &      \\[\mlrC]
     6 & 12:35 & 13:05 & 8.Y & STJ & C-12 & 8.X & F/K & C-29 & 9.A & F/K & C-29 & 7.A & F/K & C-29   &     &     &      \\[\mlrC]
     7 & 13:05 & 13:50 &     &     &      & 8.X & F/K & C-29 & 9.A & F/K & C-29 & 7.A & F/K & C-29   &     &     &      \\[\mlrC]
       & 13:50 & 14:00 & \mc{Pause}       & \mc{Pause}       & \mc{Pause}       & \mc{Pause}         & \mc{Pause}       \\[\mlrC]
     8 & 14:00 & 14:45 &     &     &      &     &     &      &     &     &      & \mc{Team, 8.~årg.} &     &     &      \\
   \bottomrule
  \end{tabular}
\end{center}

\end{document}

输出

问题(请求)

我需要帮助来改进代码和输出。真的不好而且我又累又沮丧。:-(更新:输出的问题主要是水平对齐;文本没有在每个 3 列部分居中。)

PS,我知道所有硬编码的长度都是(也是?)错误的,但我只是想不出如何修复它。

答案1

我认为你从错误的角度看待这个问题。

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


%%%%%%%%%%%%%%%%
%%            %%
%%   Pakker   %%
%%            %%
%%%%%%%%%%%%%%%%


% Skrifttypekodning for input.
%\usepackage{inputenc} % what for?

% Skrifttypekodning for output.
\usepackage[T1]{fontenc}

% Sprog.
\usepackage{babel}

% Marginer.
\usepackage[
  hmargin = 2.0cm,
  vmargin = 2.6cm
]{geometry}

% Tabeller.
\usepackage{
  booktabs,
}

% Mikrotypografiudvidelser til pdfTeX.
\usepackage{microtype}


%%%%%%%%%%%%%%%%%
%%             %%
%%   Makroer   %%
%%             %%
%%%%%%%%%%%%%%%%%

\newcommand{\lect}[3]{%
  \makebox[1.5em][l]{#1}\makebox[3.5em]{#2}\makebox[2em][r]{#3}%
}


% Fjerner ligaturer ved `f'.
\DisableLigatures[f]{encoding = T1}

% Opsætning af sidehoved og -fod.
\pagestyle{empty}


%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                      %%
%%   Selve dokumentet   %%
%%                      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%


\begin{document}

\begin{center}
  \bfseries
  \Huge
  Skema for skoleåret~2021/2022
\end{center}
\begin{center}
\begin{tabular}{ @{} *{7}{c} @{} }
\toprule
Lektion & Tidsrum & Mandag & Tirsdag & Onsdag & Torsdag & Fredag \\
\midrule
1 & 7:55--8:40 & 
  \lect{8.Y}{F/K}{C-29} &
                        &
  \lect{9.C}{F/K}{C-29} &
  \lect{7.B}{F/K}{C-29} &
  \lect{8.X}{MAT}{C-11} \\
\addlinespace
2 & 8:40--9:25 &
  \lect{8.Y}{F/K}{C-29} &
  \lect{8.X}{MAT}{C-11} &
  \lect{9.C}{F/K}{C-29} &
  \lect{7.B}{F/K}{C-29} &
                        \\
\addlinespace
  & 9:25--9:40 & Pause & Pause & Pause & Pause & Pause \\
\addlinespace
3 & 9:40--10:25 &
  \lect{8.X}{MAT}{C-11} &
                        &
                        &
  \lect{9.A}{F/K}{C-29} &
  \lect{9.C}{F/K}{C-29} \\
\addlinespace
4 & 10:25--11:10 &
  \begin{tabular}{@{}c@{}}\lect{7.B}{STU}{C-16} \\ \lect{8.X}{MAT}{C-11}\end{tabular} &
  \lect{7.A}{STJ}{C-14} &
  \lect{7.A}{STJ}{C-14} &
  \lect{9.A}{STJ}{C-29} &
  \lect{9.C}{STJ}{C-29} \\
\addlinespace
  & 11:10--11:35 & Pause & Pause & Pause & Pause & Pause \\
  & 11:35--11:50 & Spisepause & Spisepause & Spisepause & Spisepause & Spisepause \\
\addlinespace
5 & 11:50--12:35 \\
\addlinespace
6 & 12:35--13:05 &
  \lect{8.Y}{STJ}{C-12} &
  \lect{8.X}{F/K}{C-29} &
  \lect{9.A}{F/K}{C-29} & 
  \lect{7.A}{F/K}{C-29} &
                        \\
\addlinespace
7 & 13:05--13:50 &
                        &
  \lect{8.X}{F/K}{C-29} &
  \lect{9.A}{F/K}{C-29} &
  \lect{7.A}{F/K}{C-29} &
                        \\
\addlinespace
  & 13:50--14:00 & Pause & Pause & Pause & Pause & Pause \\
\addlinespace
8 & 14:00--14:45 & & & & Team, 8.~årg. & \\
\bottomrule
\end{tabular}
\end{center}

\end{document}

在命令中调整大小\lect

在此处输入图片描述

相关内容