我第一次来这里所以如果我问得不正确我很抱歉。
{\scriptsize\begin{tabular}{|p{.5in}|p{.5in}|p{.5in}|p{.5in}|p{.5in}|} \hline
Alpha & Bravo & Charlie & Delta & Echo \\ \hline
Foxtrot & Gulf & Hotel & India & Juliett \\ \hline
Kilo & Lima & November & Oscar & Papa \\ \hline
\end{tabular}}\\
具体内容tabular
并不重要,项目周围的线条也不重要(事实上,我最终可能会删除它们……)但我希望能够轻松地在此列表中添加或删除项目,例如将“Mike”插入其正确位置,而无需手动调整后面所有内容的位置,同时仍将列表放在一张纸上。分页或防止分页并不重要,因为此列表位于表单中间,并且永远不会允许靠近边缘。
最终目标是有一个按字母顺序排列的项目列表,并在适用时将其圈出或突出显示...我知道我还需要处理垂直间距,并且可能居中列表看起来会更好,但我更关心如何让列表首先易于编辑。
答案1
我认为你正在寻找类似的东西
\documentclass{article}
\begin{document}
\newcommand\zz[1]{\makebox[.5in][l]{\scriptsize#1}\hfill\ignorespaces}
\begin{minipage}{2.5in}\raggedright
\zz{Alpha} \zz{Bravo} \zz{Charlie} \zz{Delta} \zz{Echo}
\zz{Foxtrot} \zz{Gulf} \zz{Hotel} \zz{India} \zz{Juliett}
\zz{Kilo} \zz{Lima}
\zz{Mike}
\zz{November} \zz{Oscar} \zz{Papa}
\end{minipage}
\end{document}
答案2
这是另一个想法。David 的想法简单得多,如果它对你有用,那就太好了!这个版本根据您的需要更灵活一些。我放了一些自由评论来解释它的工作原理。比我更好的 TeXies 可能会建议改进我的代码,但这里是:
\documentclass{article}
\usepackage{array} % required for `>` in tabular preamble
\newcount\myfield % keep track of how many fields across we are
\newcount\maxfield % maximum number of fields
\def\z{% use \z as a separator inside mylist instead of & or \\
\ifnum \myfield < \maxfield% we haven't made it across the row yet
\def\mydefer{&}% insert a standard column separator
\else% we have made it across the row
\def\mydefer{%
\global\myfield 0\relax% reset field counter
\\\hline% go to next row
}%
\fi%
\mydefer% insert the appropriate column or row separator
}
\newenvironment{mylist}[2][l]% two arguments: #1 = column-spec (optional, default `l`); #2 = number of fields per row
{% opening of environment
\myfield 0\relax% initialize at the "zeroeth" field
\maxfield #2\relax% set max fields for this environment
\scriptsize% choose font if desired
\begin{tabular}{|*{#2}{>{\global\advance\myfield 1\relax}#1|}}% #2 copies of column #1, advance field count before each cell
\hline% horizontal rule if desired
}{% closing of environment (much simpler if you decide to drop the rules)
\ifnum\myfield=0\hline\else\\\cline{1-\myfield}\fi% draw a partial rule or full rule depending on number of fields in the last row
\end{tabular}
}
\begin{document}
\begin{mylist}{5}
Alpha \z
Bravo \z
Charlie \z Delta \z Echo \z Foxtrot \z
Gulf \z Hotel \z
India \z Juliett \z Kilo \z Lima \z Mike \z November \z Oscar \z Papa
\end{mylist}
\begin{mylist}{3}
A \z Test \z for \z different \z parameters
\end{mylist}
\begin{mylist}[c]{2}
A \z Test \z for \z different \z parameters
\end{mylist}
\begin{mylist}[p{0.75in}]{2}
A \z Test \z for \z different \z parameters
\end{mylist}
\begin{mylist}[l]{7}
Alpha \z
Bravo \z
Charlie \z Delta \z Echo \z Foxtrot \z
Gulf \z Hotel \z
India \z Juliett \z Kilo \z Lima \z Mike \z November \z Oscar \z Papa
\end{mylist}
\end{document}