
我正在整理一個包含字母和字母下方的數字的表格來追蹤進度。
\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}