将打字机文本对齐到不同的行

将打字机文本对齐到不同的行

我正在整理一张带有字母的表格,字母下方有数字以跟踪进度。

\documentclass{article}
\usepackage{xcolor, placeins, cmbright}
\usepackage[margin=0.5in]{geometry}
\begin{document}
\small
\begin{tabular}{|c|c|c|} \hline
S & \texttt{\textcolor{gray}{E}\textcolor{teal}{T}\textcolor{teal}{M}\textcolor{teal}{W}\textcolor{green}{D}\textcolor{gray}{T}\textcolor{green}{K}\textcolor{teal}{K}\textcolor{teal}{E}\textcolor{green}{V}\textcolor{gray}{K}\textcolor{teal}{A}\textcolor{teal}{A}\textcolor{teal}{A}\textcolor{teal}{T}\textcolor{gray}{A}\textcolor{teal}{A}\textcolor{teal}{M}\textcolor{teal}{T}\textcolor{teal}{K}\textcolor{gray}{A}\textcolor{teal}{T}\textcolor{teal}{E}\textcolor{teal}{T}\textcolor{teal}{V}\textcolor{gray}{D}\textcolor{green}{N}\textcolor{teal}{K}\textcolor{green}{D}\textcolor{teal}{I}\textcolor{gray}{E}\textcolor{teal}{R}\textcolor{teal}{F}\textcolor{teal}{I}\textcolor{green}{P}\textcolor{gray}{S}\textcolor{teal}{L}\textcolor{teal}{I}\textcolor{teal}{Q}\textcolor{teal}{C}\textcolor{gray}{I}\textcolor{teal}{A}\textcolor{teal}{D}\textcolor{green}{P}\textcolor{teal}{T}E-\textcolor{gray}{-}\textcolor{teal}{V}\textcolor{teal}{P}\textcolor{teal}{E}\textcolor{teal}{T}\textcolor{gray}{V}\textcolor{teal}{H}\textcolor{teal}{L}\textcolor{green}{L}\textcolor{teal}{G}\textcolor{gray}{A}\textcolor{green}{T}\textcolor{green}{T}\textcolor{green}{F}\textcolor{green}{V}\textcolor{gray}{A}\textcolor{teal}{E}\textcolor{green}{V}\textcolor{teal}{T}\textcolor{teal}{P}\textcolor{gray}{A}\textcolor{teal}{T}\textcolor{green}{L}\textcolor{teal}{S}\textcolor{teal}{I}\textcolor{gray}{M}\textcolor{teal}{V}\textcolor{green}{P}\textcolor{teal}{L}\textcolor{green}{L}\textcolor{gray}{S}\textcolor{teal}{R}\textcolor{teal}{G}\textcolor{green}{L}\textcolor{teal}{N}\textcolor{gray}{E}\textcolor{teal}{R}E\textcolor{teal}{-}T-\textcolor{teal}{-}\textcolor{teal}{G}\textcolor{gray}{I}\textcolor{teal}{K}\textcolor{green}{R}\textcolor{teal}{K}\textcolor{teal}{S}\textcolor{gray}{A}\textcolor{teal}{V}\textcolor{teal}{I}\textcolor{teal}{I}\textcolor{teal}{D}} & 270
\\
S track & \texttt{176   -181   -186   -191   -196   -201   -206   -211   -216   ---221   -226   -231   -236   -241   -246   -251   -256   --259   -264   -269} & 270
\\
\hline\end{tabular}
\end{document}

其结果如下:

在此处输入图片描述

但正如您所见,两列中的文本没有对齐。

更明确地说,1应该位于上方正下方E。但是,它稍微向左移动了一点。269也出现在错误的位置。

问题在于,即使是等宽字体,空间也会被区别对待\texttt

我尝试过很多不同地方的解决方案,例如表格中多行对齐(不是唯一的地方)但我不知道如何让数字对齐。

我曾尝试将字母和数字放入大表格中 100 列宽的单元格中,但字母之间的空间太大,导致表格变得难以阅读。

我也尝试过flushleft但是失败了。

有什么方法可以告诉 LaTeX,将其1直接放在下面E吗?

我在中心柱上使用时遇到了一些麻烦l,但对于中心柱的右侧似乎不起作用。

只要成品看起来不错,我愿意接受彻底的重新设计。

答案1

两行中的元素数量不一致,这是错位的主要原因;第一行有 100 个字符,第二行有 101 个字符(如果包括空格)。以下是逐字的视觉效果:

ETMWDTKKEVKAAATAAMTKATETVDNKDIERFIPSLIQCIADPTE--VPETVHLLGATTFVAEVTPATLSIMVPLLSRGLNERE-T--GIKRKSAVIID
176 -181 -186 -191 -196 -201 -206 -211 -216 ---221 -226 -231 -236 -241 -246 -251 -256 --259 -264 -269

最好重写代码,使其更清晰易读,这样可以更好地隔离错误。我不熟悉内容,所以将其拆分为与数字匹配的宽度。

\documentclass{article}

\usepackage{xcolor, cmbright}
\usepackage[margin=0.5in]{geometry}

\begin{document}

\small
\begin{tabular}{ | c | l | c | }
  \hline
  S & \ttfamily
      \textcolor{gray}{E}\textcolor{teal}{T}\textcolor{teal}{M}%
      \textcolor{teal}{W}\textcolor{green}{D}\textcolor{gray}{T}\textcolor{green}{K}%
      \textcolor{teal}{K}\textcolor{teal}{E}\textcolor{green}{V}\textcolor{gray}{K}%
      \textcolor{teal}{A}\textcolor{teal}{A}\textcolor{teal}{A}\textcolor{teal}{T}%
      \textcolor{gray}{A}\textcolor{teal}{A}\textcolor{teal}{M}\textcolor{teal}{T}%
      \textcolor{teal}{K}\textcolor{gray}{A}\textcolor{teal}{T}\textcolor{teal}{E}%
      \textcolor{teal}{T}\textcolor{teal}{V}\textcolor{gray}{D}\textcolor{green}{N}%
      \textcolor{teal}{K}\textcolor{green}{D}\textcolor{teal}{I}\textcolor{gray}{E}%
      \textcolor{teal}{R}\textcolor{teal}{F}\textcolor{teal}{I}\textcolor{green}{P}%
      \textcolor{gray}{S}\textcolor{teal}{L}\textcolor{teal}{I}\textcolor{teal}{Q}%
      \textcolor{teal}{C}\textcolor{gray}{I}\textcolor{teal}{A}\textcolor{teal}{D}%
      \textcolor{green}{P}\textcolor{teal}{T}E-%
      \textcolor{gray}{-}\textcolor{teal}{V}\textcolor{teal}{P}\textcolor{teal}{E}%
      \textcolor{teal}{T}\textcolor{gray}{V}\textcolor{teal}{H}\textcolor{teal}{L}%
      \textcolor{green}{L}\textcolor{teal}{G}\textcolor{gray}{A}\textcolor{green}{T}%
      \textcolor{green}{T}\textcolor{green}{F}\textcolor{green}{V}\textcolor{gray}{A}%
      \textcolor{teal}{E}\textcolor{green}{V}\textcolor{teal}{T}\textcolor{teal}{P}%
      \textcolor{gray}{A}\textcolor{teal}{T}\textcolor{green}{L}\textcolor{teal}{S}%
      \textcolor{teal}{I}\textcolor{gray}{M}\textcolor{teal}{V}\textcolor{green}{P}%
      \textcolor{teal}{L}\textcolor{green}{L}\textcolor{gray}{S}\textcolor{teal}{R}%
      \textcolor{teal}{G}\textcolor{green}{L}\textcolor{teal}{N}\textcolor{gray}{E}%
      \textcolor{teal}{R}E\textcolor{teal}{-}T%
      -\textcolor{teal}{-}\textcolor{teal}{G}\textcolor{gray}{I}\textcolor{teal}{K}%
      \textcolor{green}{R}\textcolor{teal}{K}\textcolor{teal}{S}\textcolor{gray}{A}%
      \textcolor{teal}{V}\textcolor{teal}{I}\textcolor{teal}{I}\textcolor{teal}{D} & 270 \\
  S track & \ttfamily
      176~%
      -181~%
      -186~%
      -191~%
      -196~%
      -201~%
      -206~%
      -211~%
      -216~%
      ---221~%
      -226~%
      -231~%
      -236~%
      -241~%
      -246~%
      -251~%
      -256~%
      --259~%
      -264~%
      -269 & 270 \\
  \hline
\end{tabular}

\end{document}

相关内容