
私は 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
。実際に修正を実装するときは、これらを元の状態に戻す必要があります。
コードにはすでにタイトルのテストがありましたそして場所が欠落していたので、位置が空の場合とそうでない場合の場所が空の場合の2つの追加テストをネストしました。質問で指定された場所が空だったので、このようにしました。または欠落しているフィールドの条件ではなく、そして状態。
こちらが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}