
所以我對 TeX 完全陌生,剛開始使用我在 github 上找到的履歷模板。在該範本中,有一個帶有環境“cventries”和命令“cventry”的類別檔案:
\newcommand*{\cventry}[5]{
\setlength\tabcolsep{0pt}
\setlength{\extrarowheight}{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} L{12.5cm} R{4.5cm}}
\ifempty{#2#3}
{\entrypositionstyle{#1} & \entrydatestyle{#4} \\}
{\entrytitlestyle{#2} & \entrylocationstyle{#3} \\
\entrypositionstyle{#1} & \entrydatestyle{#4} \\}
\multicolumn{2}{L{17cm}}{\descriptionstyle{#5}} \\
\end{tabular*}
}
現在,這基本上在螢幕上呈現如下
Title Location
Position Date
Description
但每當我不填寫位置或日期欄位時,我希望它像這樣呈現:
Title Date
Description
因此,簡而言之,我想知道是否需要執行另一個命令或使用 \ifempty 的某些組合才能實現此目的。預先感謝您的任何幫助。
哦,如果您需要任何其他背景來回答我的問題,這是完整的類別文件
答案1
僅提供程式碼片段會使其變得困難,因為我們必須想像所有未定義的命令可能意味著什麼。
首先,我假設問題中存在拼字錯誤,您想要替代格式,如果位置或地點缺席(因為如果日期缺席,為什麼想要日期)。
然後我假設這些\Xstyle
命令只是文字樣式......這是一個非常安全的假設。
我還假設了 的合理定義\ifempty
,但這可能不是您的班級所假設的。
最後,我必須修改表格的格式,因為L
和R
列沒有定義。在這些情況下,我將這些列類型替換為p
.當實際實施修復時,您應該將它們改回原來的樣子。
程式碼已經有一個測試 if title和location 不存在,因此我嵌套了兩個額外的測試,判斷該位置是否為空,如果不是,則判斷該位置是否為空。我這樣做是因為問題指定了或者缺失字段的條件,而不是和狀態.
這是 MWE。
\documentclass{article}
\usepackage{array}
\def\entrypositionstyle#1{\textit{#1}}
\def\entrytitlestyle#1{\textbf{#1}}
\def\entrylocationstyle#1{\textit{\textbf{#1}}}
\def\entrydatestyle#1{\textsc{#1}}
\def\descriptionstyle#1{\textup{#1}}
\def\ifempty#1#2#3{\ifx\relax#1\relax#2\else#3\fi}
\newcommand*{\cventry}[5]{
\setlength\tabcolsep{0pt}
\setlength{\extrarowheight}{0pt}
% \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} L{12.5cm} R{4.5cm}}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} p{12.5cm} p{4.5cm}}
\ifempty{#2#3}
{\entrypositionstyle{#1} & \entrydatestyle{#4} \\}% WHEN TITLE & LOCATION EMPTY
{%
\ifempty{#1}{\entrytitlestyle{#2} & \entrydatestyle{#4} \\}% WHEN POSITION EMPTY
{%
\ifempty{#3}{\entrytitlestyle{#2} & \entrydatestyle{#4} \\}% WHEN LOC EMPTY
{%
\entrytitlestyle{#2} & \entrylocationstyle{#3} \\
\entrypositionstyle{#1} & \entrydatestyle{#4} \\%
}
}
}
% \multicolumn{2}{L{17cm}}{\descriptionstyle{#5}} \\
\multicolumn{2}{p{17cm}}{\descriptionstyle{#5}} \\
\end{tabular*}
}
\begin{document}
\cventry{position}{title}{location}{date}{description}
\par\hrulefill\par
\cventry{position}{}{}{date}{description}
\par\hrulefill\par
\cventry{}{title}{location}{date}{description}
\par\hrulefill\par
\cventry{position}{title}{}{date}{description}
\end{document}