自訂命令中“這裡沒有結束行”

自訂命令中“這裡沒有結束行”

我正在用 LaTeX 創建一份簡歷,並定義了一個允許我輸入我的工作經驗的命令。唯一的問題是,每當我嘗試使用逐項列表時,如下所示,我都會得到"! LaTeX Error: There's no line here to end.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... To Be Added}".\\由於某種原因,我還必須手動添加換行符。

我的 tex 文件的程式碼:

\section{Related Experience}

\begin{entrylist}
  \experience
    {Jan 2014 – Present}
    {IT Systems}
    {Chocolate Covered Alien Co.; Mars, PA}
    {\textbf{Responsibilities:}\\
    \begin{itemize}
        \item Cook aliens to a nice texture
        \item Chocolate cover said aliens
    \end{itemize}}
    {\textbf{Key Achievements:}\\
    \begin{itemize}
        \item Ate chocolate covered aliens without the boss finding out
    \end{itemize}}
    \end{entrylist}

我的班級文檔的代碼:

\newenvironment{entrylist}{%
    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ll}
}{%
    \end{tabular*}
}

\newcommand{\experience}[5]{%
    \textbf{#1}&\parbox[t]{12cm}{%
        \textbf{#2}\\%
        \textit{#3}\\%
        #4\\%
        #5\vspace{\parsep}%
    }\\}

答案1

問題是這\begin{itemize} ... \end{itemize}不是一行文本,所以你不能放在\\它後面。環境是獨立的,因此它們總是放置在一個段落之後和另一個段落之前。

這意味著\\您使用 after#4導致了錯誤。另外,如果您使用的是 ,則不需要\\在巨集末尾\vspace{\parsep}。將巨集重新定義為:

\newcommand{\experience}[5]{%
    \textbf{#1}&\parbox[t]{12cm}{%
        \textbf{#2}\newline%
        \textit{#3}\newline%
        #4%
        #5\vspace{\parsep}%
}}

編輯:然而,這可能會導致另一個問題(警告)。現在,表格的第二列寬 12 厘米,第一列可以拉伸到任意長度。因此,每次第一列中的文字「推開」第二列時,您都會得到一個水平盒子溢出。要擺脫水平盒過滿的情況,您還必須為第一列定義固定長度。您必須以這樣的方式進行操作,即兩列一起不會超過線寬。你可以這樣做:

\newcommand{\experience}[5]{%
    \parbox[t]{0.3\linewidth}{\textbf{#1}}&\parbox[t]{0.63\linewidth}{%
        \textbf{#2}\newline%
        \textit{#3}\newline%
        #4%
        #5\vspace{\parsep}%
}}

其中 0.3 + colsep + 0.63 大約為 1 線寬。

相關內容