考虑以下代码:
\documentclass[
a4paper,
12pt
]{article}
\usepackage[
hmargin=2.4cm,
vmargin=3cm
]{geometry}
\usepackage{amssymb}
\usepackage{enumerate} % better to use enumitem
\usepackage{totcount}
\usepackage[
colorlinks=true,
urlcolor=black
]{hyperref}
\newcommand*\ops[1]{\textbf{\textsf{#1}}}
\newcommand*\options[3]{\color{#1}\ops{#2}\fontsize{#3}{#3}}
\newcommand*\film[4]{%
\item \fontsize{12pt}{12pt} \selectfont \textsf{[#4] \enskip \href{#1}{#2}~(#3)}}
\setlength{\labelsep}{0em}
\renewcommand*\labelenumi{\options{blue}{\ops}{10pt} $\maltese$ \quad}
\regtotcounter{enumi}
\begin{document}
\begin{enumerate}
\film{http://www.imdb.com/title/tt0134273/}{8MM}{1999}{6,4}
\film{http://www.imdb.com/title/tt0050083/}{12 Angry Men}{1957}{8,9}
\item\fontsize{12pt}{12pt}\selectfont \textsf{[2,1] \enskip \href{http://www.imdb.com/title/tt0057181/}{Incredibly Strange Creatures Who Stopped Living and Became Mixed-Up}}\\ \verb++\hspace{9.9mm} \textsf{{\href{http://www.imdb.com/title/tt0057181/}{Zombies, The}} (2006)}
\end{enumerate}
\noindent I have \total{enumi}~films.
\end{document}
如果标题太长,如何自动换行和如果标题跨越多行,是否需要将其左对齐(正如我对最后一项手动完成的那样)?
后续问题
考虑一下 David 的代码:
\documentclass[
a4paper,
12pt
]{article}
\usepackage[
hmargin=2.4cm,
vmargin=3cm
]{geometry}
\usepackage{amssymb}
\usepackage{enumitem}
\usepackage{totcount}
\usepackage[
colorlinks=true,
urlcolor=black
]{hyperref}
\newcommand*\film[4]{%
\item[\refstepcounter{enumi}\textcolor{blue}{$\maltese$}\quad\textsf{[#4]}] \textsf{\href{#1}{#2}~(#3)}}
\regtotcounter{enumi}
\begin{document}
\begin{enumerate}[
leftmargin=5em,
labelindent=-5em
]
\film{http://www.imdb.com/title/tt0134273/}{8MM}{1999}{6,4}
\film{http://www.imdb.com/title/tt0050083/}{12 Angry Men}{1957}{8,9}
\film{http://www.imdb.com/title/tt0057181/}{Incredibly Strange Creatures Who Stopped Living and Became Mixed-Up Zombies, The}{2006}{2,1}
\end{enumerate}
\noindent I have \total{enumi}~films.
\end{document}
enumerate
为了获得与初始代码相同的对齐,我必须提供哪些选项?
问题在于,使用 David 的方法,符号和 [x,y] 之间以及 [x,y] 和标题之间的空间太小。如果我尝试添加一些空间,符号就会进入左边距。
更新 2
最后一个问题:我想要一个\if
循环;类似的东西
\if \total{enumi} = 1
I have 1~film.
\else
I have \total{enumi}~films.
\fi
但它不起作用。我该怎么做?
答案1
如果您使用,\fontsize
则需要在其后跟上,\selectfont
并且在两个参数中使用相同的长度是危险的,因为通常会导致行距不一致。
\documentclass[
a4paper,
12pt
]{article}
\usepackage[
hmargin=2.4cm,
vmargin=3cm
]{geometry}
\usepackage{amssymb}
\usepackage{enumitem} % better to use enumitem
\usepackage{totcount}
\usepackage[
colorlinks=true,
urlcolor=black
]{hyperref}
\newcommand*\film[4]{%
\item[\refstepcounter{enumi}\textcolor{blue}{$\maltese$} \textsf{[#4]}] \textsf{\href{#1}{#2}~(#3)}}
\regtotcounter{enumi}
\begin{document}
\begin{enumerate}[leftmargin=5em,labelindent=-5em]
\film{http://www.imdb.com/title/tt0134273/}{8MM}{1999}{6,4}
\film{http://www.imdb.com/title/tt0050083/}{12 Angry Men}{1957}{8,9}
\film{http://www.imdb.com/title/tt0057181/}{Incredibly Strange Creatures Who Stopped Living and Became Mixed-Up Zombies, The}{2006}{2,1}
\end{enumerate}
I have \total{enumi}~films.
\end{document}
或更加分散
\newcommand*\film[4]{%
\item[\refstepcounter{enumi}\textcolor{blue}{$\maltese$}\hspace{2em}\textsf{[#4]}] \textsf{\href{#1}{#2}~(#3)}}
..
\begin{enumerate}[leftmargin=15em,labelindent=-10em,align=left,labelwidth=10em]