对角线表头的表格间距问题

对角线表头的表格间距问题

我想在单词上放置对角线标记。我尝试使用表格来实现这一点,我对结果几乎很满意:

在此处输入图片描述

但如您所见,句子的单词之间的间距太大。我尝试通过将第一行的值放入来解决这个问题,\makebox为它们提供一个空白width部分2\tabcolsep

\documentclass{scrreprt}

\usepackage{graphicx}

\begin{document}

% \newcommand*{\diaghead}[1]{\rotatebox{45}{\texttt{#1}}}
\newcommand*{\diaghead}[1]{\makebox[2\tabcolsep]{\rotatebox{45}{\texttt{#1}}}}

\begin{table}
    \begin{tabular}{l l l l l l l l l l l l l l}
    % \begin{tabular}{c c c c c c c c c c c c c c}
    % \begin{tabular}{r r r r r r r r r r r r r r}
        \diaghead{O} & \diaghead{O} & \diaghead{O} & \diaghead{B-Customer} & \diaghead{I-Customer} & \diaghead{I-Customer} & \diaghead{I-Customer} & \diaghead{I-Customer} & \diaghead{O} & \diaghead{O} & \diaghead{O} & \diaghead{O} & \diaghead{O} & \diaghead{...} \\
        Please & deliver & to & Example & Company & \& & Co. & Ltd. & Our & terms & and  & conditions & apply & ...
    \end{tabular}
    \caption{Example for the BIO-Notation.}
\end{table}
\end{document}

结果是:

在此处输入图片描述

由于标记重叠,似乎仍缺少一些间距。

有人能帮我提供适当的间距吗?或者除了使用之外,还有其他解决方案可以在单词上方获得对角标记tikz吗?

答案1

我可以修复它:

在此处输入图片描述

关键是添加可选的排列参数(发现这里(德语)改为\makebox(我使用l)。我还将 设置\tabcolsep4pt单词之间的较小间距。以下是相应的 MWE:

\documentclass{scrreprt}

\usepackage{graphicx}

\begin{document}

\newcommand*{\diaghead}[1]{\makebox[2\tabcolsep][l]{\rotatebox{45}{\texttt{#1}}}}
\begin{table}
    \setlength\tabcolsep{4pt}
    \begin{tabular}{c c c c c c c c c c c c c c}
        \diaghead{O} & \diaghead{O} & \diaghead{O} & \diaghead{B-Customer} & \diaghead{I-Customer} & \diaghead{I-Customer} & \diaghead{I-Customer} & \diaghead{I-Customer} & \diaghead{O} & \diaghead{O} & \diaghead{O} & \diaghead{O} & \diaghead{O} & \diaghead{...} \\
        Please & deliver & to & Example & Company & \& & Co. & Ltd. & Our & terms & and  & conditions & apply & ...
    \end{tabular}
    \caption{Example for the BIO-Notation.}
\end{table}
\end{document}

我进一步改进了它,使用包tabularx来适应\textwidth(因为最后一个对角线标记可能会超出它)。我还添加了\overbrace\vphantom{gh}(来自答案)将括号对齐到同一高度。另外,\scriptsize由于一些单词较短,我缩小了括号:

\documentclass{scrreprt}

\usepackage{graphicx}
\usepackage{tabularx}

\begin{document}

\newcommand*{\diaghead}[1]{\makebox[2\tabcolsep][l]{\rotatebox{45}{\texttt{#1}}}}
\newcommand*{\textovbrace}[1]{$\tiny{\overbrace{\mbox{\normalsize{\vphantom{gh}#1}}}}$}
\begin{table}
    \setlength\tabcolsep{4pt}
    \begin{tabularx}{\textwidth}{c c c c c c c c c c c c c X}
        \diaghead{O} & \diaghead{O} & \diaghead{O} & \diaghead{B-Customer} & \diaghead{I-Customer} & \diaghead{I-Customer} & \diaghead{I-Customer} & \diaghead{I-Customer} & \diaghead{O} & \diaghead{O} & \diaghead{O} & \diaghead{O} & \diaghead{O} & \diaghead{...} \\
        \textovbrace{Please} & \textovbrace{deliver} & \textovbrace{to} & \textovbrace{Example} & \textovbrace{Company} & \textovbrace{\&} & \textovbrace{Co.} & \textovbrace{Ltd.} & \textovbrace{Our} & \textovbrace{terms} & \textovbrace{and } & \textovbrace{conditions} & \textovbrace{apply} & \textovbrace{...}
    \end{tabularx}
    \caption{Example for the BIO-Notation.}
\end{table}
\end{document}

这是我的最终结果:

在此处输入图片描述

相关内容