表列之間的符號

表列之間的符號

我需要在表格中的兩列之間添加一些符號。下圖是需要的輸出。我不知道如何實現這一點。

輸出影像

谷歌搜尋給了我問題OP想要類似的東西。然而,該解決方案對於我的使用來說太窄了,因為我想在某些行而不是所有行中自動執行此操作。有其他方法可以做到這一點嗎?

答案1

沒有額外的列並保留原始間距:

\documentclass{article}
\usepackage{array}

\begin{document}

\noindent\begin{tabular}{|ccc|cc|}
\hline
\multicolumn{1}{|c@{\hspace*{\tabcolsep}\makebox[0pt]{-}}}{a}
  & b & c & d & e \\
\hline
a & \multicolumn{1}{c@{\hspace*{\tabcolsep}\makebox[0pt]{-}}}{b}
 & c & d & e \\
\hline
\end{tabular}

\noindent\begin{tabular}{|ccc|cc|}
\hline
a & b & c & d & e \\
\hline
a & b & c & d & e \\
\hline
\end{tabular}

\end{document}

在此輸入影像描述

這個想法是使用零寬度的方塊來設定插入符號的語法\multicolumn@{...}

答案2

該解決方案採納了 Steven 的建議,並透過添加額外的列來細化間距:

\documentclass[a4paper]{article}

\begin{document}

\setlength{\tabcolsep}{2pt}

\begin{table}[h]
\begin{tabular}{|ccccccc|ccccc|}
\hline
 & a & - & b &   & c & & & d & & e &\\
\hline
 & p &   & q & - & r & & & s & & t &\\
\hline
\end{tabular}
\end{table}

\end{document}

在此輸入影像描述

相關內容