好的,标题不太清楚,所以我会尝试在这里说得更清楚一些。
我已使用提供的答案在 cventry 中成功添加了徽标此踩。我使用的命令是
\newcommand*{\cventrylogo}[8][.25em]{%
\cvitem[#1]{#2}{%
{\bfseries#3}%
\ifthenelse{\equal{#4}{}}{}{, {\slshape#4}}%
\ifthenelse{\equal{#5}{}}{}{, #5}%
\ifthenelse{\equal{#6}{}}{}{, #6.}%
\ifthenelse{\equal{#7}{}}{}{\hfill \includegraphics[scale=0.25]{#7}}%
\strut%
\ifx&%
\else{\newline{}\begin{minipage}[t]{\linewidth}\small#8\end{minipage}}\fi}}
如您所见,徽标在那里,但如果它前面的文本很长,它就会被推到下一行。我想避免这种情况,并将徽标固定在页面的右侧,文本自然地放在下一行。
我应该如何修改命令才能得到这个结果?
如果您需要测试某些内容,这里有一个最小代码示例:
\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{classic}
\moderncvcolor{blue}
\usepackage{graphicx}
\graphicspath{ {images/} }
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[scale=0.85]{geometry}
\name{John}{Doe}
\address{Address}{Address}{Country}
\phone[mobile]{+1234567890}
\phone[fixed]{+1234567890}
\email{[email protected]}
\photo[64pt][0.4pt]{picture}
%cventrylogo
\newcommand{\cventrylogo}[9][.25em]{%
\cvitem[#1]{#2}{%
{\bfseries#3}%
\ifthenelse{\equal{#4}{}}{}{, {\slshape#4}}%
\ifthenelse{\equal{#5}{}}{}{, #5}%
\ifthenelse{\equal{#6}{}}{}{, #6.}%
\ifthenelse{\equal{#7}{}}{}{%
\ifthenelse{\equal{#8}{}}{}{\hfill \raisebox{-0.5\height}{\includegraphics[width=#8]{#7}}}}%
\strut%
\ifx	&%
\else{\newline{}\begin{minipage}[t]{\linewidth}\small#9\end{minipage}}\fi} }
\begin{document}
\makecvtitle
\section{Work Experience}
\section{Education}
\cventrylogo{Date1 - Date2}{Very long name just to make things clearer}{Name of the institution}{Address of the institution}{}{logo}{16mm}{Very long and interesting description of what I did there}
\end{document}
答案1
就是这样:
我使用了一个minipage
方法。首先我检查参数是否#7
存在,如果存在,则创建一个具有宽度的迷你页面\linewidth-#8-1em
(宽度1em
是任意的,只是为了在文本和图像之间保留一个小的空间)。
然后内容就排版正常了。
然后,再次检查是否存在#7
,如果是,则关闭第一个小页面并#8
打开另一个具有宽度的小页面并放置图像。
编辑:
我必须修补\cvitem
宏以纠正垂直对齐。因为我在 的右侧使用了[t]
op 对齐的s ,所以 LaTeX 将左侧的基线与 对齐,从而导致错位。因此我修补了宏以包含具有相同op 对齐的 。minipage
\cvitem
\vspace{0pt}
\cvitem
minipage
[t]
\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{classic}
\moderncvcolor{blue}
\usepackage{graphicx}
\graphicspath{ {images/} }
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[scale=0.85]{geometry}
\name{John}{Doe}
\address{Address}{Address}{Country}
\phone[mobile]{+1234567890}
\phone[fixed]{+1234567890}
\email{[email protected]}
\photo[64pt][0.4pt]{example-image}
\expandafter\patchcmd\csname\string\cvitem\endcsname
{\hintstyle{#2}}
{\hintstyle{\begin{minipage}[t]{\dimexpr\linewidth-2\tabcolsep\relax}\vspace{0pt}#2\end{minipage}}}
{}
{}%
%cventrylogo
\newcommand{\cventrylogo}[9][.25em]{%
\cvitem[#1]{#2}{%
\ifthenelse{\equal{#7}{}}%
{}{% V-V arbitrary space
\begin{minipage}[t]{\dimexpr\linewidth-#8-1em}%
\vspace{0pt}%
}%
{\bfseries#3}%
\ifthenelse{\equal{#4}{}}{}{, {\slshape#4}}%
\ifthenelse{\equal{#5}{}}{}{, #5}%
\ifthenelse{\equal{#6}{}}{}{, #6.}%
\strut%
\ifx	&%
\else{\newline{}\begin{minipage}[t]{\linewidth}\small#9\end{minipage}}\fi
\ifthenelse{\equal{#7}{}}%
{}{%
\end{minipage}\hfill%
\begin{minipage}[t]{#8}%
\vspace{0pt}%
\includegraphics[width=#8]{#7}%
\end{minipage}%
}%
} }
\begin{document}
\makecvtitle
\section{Work Experience}
\section{Education}
\cventrylogo{Date1 - Date2}{Very long name just to make things clearer}{Name of the institution}{Address of the institution}{}{example-image}{16mm}{Very long and interesting description of what I did there}
\end{document}