我有一个详细清单:
\begin{itemize}
\item First item
\item Second item
\end{itemize}
我想将此列表放在页面中央附近。但我仍然希望项目符号左对齐。我该怎么做?
答案1
如果你的列表必须跨越页面边界,那么你可以调整leftmargin
并rightmargin
提供enumitem
- 将它们设置为相等的值:
\documentclass{article}
\usepackage{enumitem,lipsum}
\begin{document}
\lipsum[1]
\begin{itemize}
\item First item
\item Second item
\end{itemize}
\lipsum[2]
\begin{itemize}[leftmargin=.4\linewidth,rightmargin=.4\linewidth]
\item First item
\item Second item
\end{itemize}
\lipsum[3]
\end{document}
您可以根据列表项的宽度调整边距。
答案2
无需猜测:
\documentclass{article}
\usepackage{environ}
\usepackage{lipsum} % just for the example
\NewEnviron{centeritemize}{%
\global\centeritemizewd=0pt
\setbox0=\vbox{
\renewcommand{\item}[1][]{\centeritemizeitem}
\BODY\item\centeritemize
}
\global\advance\centeritemizewd\labelwidth
\begin{center}
\begin{minipage}{\centeritemizewd}
\leftmargini=0pt
\begin{itemize}
\BODY
\end{itemize}
\end{minipage}
\end{center}
}
\newdimen\centeritemizewd
\def\centeritemizeitem#1\item#2{%
\setbox2=\hbox{#1}%
\ifdim\wd2>\centeritemizewd
\global\centeritemizewd=\wd2
\fi
\ifx#2\centeritemize
% end the recursion
\else
\expandafter\centeritemizeitem
\fi
}
\begin{document}
\lipsum*[2]
\begin{centeritemize}
\item First item
\item Second item
\end{centeritemize}
\lipsum[2]
\end{document}
限制:环境中不允许有空行centeritemize
。
不要使用它。没有理由这么做。
答案3
\begin{center}
\begin{minipage}{.5\textwidth}
\begin{itemize}
\item First item
\item Second item
\end{itemize}
\end{minipage}
\end{center}
答案4
我能看到两种解决方案,emulating
itemize 环境加上一个tabular
用于短项目的环境,或者加上一个tabulary
环境,固定项目的最大宽度并在规定的宽度自动换行。它还允许\par
s。
例子:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{lipsum}
\usepackage{tabulary}
\usepackage[textwidth = 16cm, nomarginpar, showframe]{geometry}
\begin{document}
\lipsum[2]
\begin{center}
\begin{tabulary}{0.6\linewidth}{@{\textbullet\hskip\labelsep}L@{}}
A very long first item, a very long first item, a very long first item, a very long first item,
\par
To be continued… \\
Second item \\
A slightly longer third item
\end{tabulary}
\end{center}
\lipsum[3]
\begin{center}
\begin{tabulary}{0.6\linewidth}{@{\textbullet\hskip\labelsep}L@{}}
A not so long first item\\
Second item \\
A slightly longer third item
\end{tabulary}
\end{center}
\lipsum[4]
\begin{center}
\begin{tabular}{@{\textbullet\hskip\labelsep}l@{}}
A not so long first item\\
Second item \\
A slightly longer third item
\end{tabular}
\end{center}
\end{document}