添加标题和地址对齐,moderncv

添加标题和地址对齐,moderncv

我正在用 修改我的求职信moderncv。特别是,我想添加一个标题行,使正文对齐并将两个地址对齐到同一高度(公司地址在左上角,我的地址在右上角)。我找到了几篇与主题相关的帖子,并将代码部分添加到我的 TeX 文件中。它们都可以单独使用,但不能组合使用,我不明白为什么。这是 MWE:

\documentclass[12pt,a4paper,sans]{moderncv}       
\usepackage[ngerman]{babel}

\usepackage{tabularx}

% moderncv themes
\moderncvstyle{classic}
\moderncvcolor{blue}                             

\setlength{\hintscolumnwidth}{3.3cm} 

% character encoding
\usepackage[utf8]{inputenc}                      
\name{Name}{name}
\title{Lebenslauf}                             
\address{...}{...}
\phone[mobile]{...}                   
\email{Mail}  

%Justification    
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd{\makeletterhead}% <cmd>
   {\raggedright \@opening}% <search>
  {\@opening}% <replace>
  {}{}% <success><failure>
\makeatother        




 %Adds title                                         
   \makeatletter 
\patchcmd{\makeletterhead}{%search
          \raggedright%
  \@opening\\[1.5em]%
        }{%replace
          \raggedright%
  \textbf{\@title}\\[1.5em]
  \@opening\\[1.5em]%
        }{%success
  }{%failure
  }
\makeatother       


 %Should align both adresses on the same "height"
 \makeatletter
\renewcommand*{\makeletterhead}{%
  % recompute lengths (in case we are switching from letter to resume, or vice versa)
  \recomputeletterlengths%
    % recipient block
  \begin{minipage}[t]{.49\textwidth} % <================================
    \raggedright%
    \addressfont%
    {\bfseries\upshape\@recipientname}\\%
    \@recipientaddress%
  \end{minipage}
  % sender contact info
  \hfill%
  \begin{minipage}[t]{.49\textwidth}% <=================================
    % optional detailed information
    \if@details%
      \raggedleft%
      \addressfont\textcolor{color2}{%
        {\bfseries\upshape\@firstname~\@lastname}\@firstdetailselementfalse%
        % optional detailed information
        \ifthenelse{\isundefined{\@addressstreet}}{}{\makenewline\addresssymbol\@addressstreet%
          \ifthenelse{\equal{\@addresscity}{}}{}{\makenewline\@addresscity}% if \addresstreet is defined, \addresscity and addresscountry will always be defined but could be empty
          \ifthenelse{\equal{\@addresscountry}{}}{}{\makenewline\@addresscountry}}%
        \collectionloop{phones}{% the key holds the phone type (=symbol command prefix), the item holds the number
          \makenewline\csname\collectionloopkey phonesymbol\endcsname\collectionloopitem}%
        \ifthenelse{\isundefined{\@email}}{}{\makenewline\emailsymbol\emaillink{\@email}}%
        \ifthenelse{\isundefined{\@homepage}}{}{\makenewline\homepagesymbol\httplink{\@homepage}}%
        \ifthenelse{\isundefined{\@extrainfo}}{}{\makenewline\@extrainfo}}\fi%
      \\[1em] % <=======================================================
      \@date % <========================================================
    \end{minipage}\\[2em] 
  % opening
% \raggedright% <=======================================================
  \@opening\\[1.5em]%
  % ensure no extra spacing after \makelettertitle due to a possible blank line
%  \ignorespacesafterend% not working
  \hspace{0pt}\par\vspace{-\baselineskip}\vspace{-\parskip}}
\makeatother


\begin{document}

\makecvtitle

\section{Foo}

\section{Foo2}
\subsection*{FooFoo}

\clearpage

%-----       letter       ---------------------------------------------------------
% recipient data
\recipient{Company Recruitment team}{Company, Inc.\\123 somestreet\\some city}
\title{Heading should look like this} % <===============================
\date{January 01, 1984}
\opening{Dear Sir or Madam,}
\closing{Yours faithfully,}
\enclosure[Attached]{curriculum vit\ae{}}
\makelettertitle

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ullamcorper 
neque sit amet lectus facilisis sed luctus nisl iaculis. Vivamus at neque 
arcu, sed tempor quam. Curabitur pharetra tincidunt tincidunt. Morbi 
volutpat feugiat mauris, quis tempor neque vehicula volutpat. Duis 
tristique justo vel massa fermentum accumsan. Mauris ante elit, feugiat 
vestibulum tempor eget, eleifend ac ipsum. Donec scelerisque lobortis 
ipsum eu vestibulum. Pellentesque vel massa at felis accumsan rhoncus.

Suspendisse commodo, massa eu congue tincidunt, elit mauris pellentesque 
orci, cursus tempor odio nisl euismod augue. Aliquam adipiscing nibh ut 
odio sodales et pulvinar tortor laoreet. Mauris a accumsan ligula. 
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per 
inceptos himenaeos. Suspendisse vulputate sem vehicula ipsum varius nec 
tempus dui dapibus. Phasellus et est urna, ut auctor erat. Sed tincidunt 
odio id odio aliquam mattis. Donec sapien nulla, feugiat eget adipiscing 
sit amet, lacinia ut dolor. Phasellus tincidunt, leo a fringilla 
consectetur, felis diam aliquam urna, vitae aliquet lectus orci nec 
velit. Vivamus dapibus varius blandit.

Duis sit amet magna ante, at sodales diam. Aenean consectetur porta risus 
et sagittis. Ut interdum, enim varius pellentesque tincidunt, magna 
libero sodales tortor, ut fermentum nunc metus a ante. Vivamus odio leo, 
tincidunt eu luctus ut, sollicitudin sit amet metus. Nunc sed orci 
lectus. Ut sodales magna sed velit volutpat sit amet pulvinar diam 
venenatis.

Albert Einstein discovered that $e=mc^2$ in 1905.

\[ e=\lim_{n \to \infty} \left(1+\frac{1}{n}\right)^n \]


\end{document}

封面是对齐的,地址在同一高度,但没有涉及标题。也许有人知道如何解决这个问题。我不太了解参数的变化\patchcmd,也许存在问题。

在此处输入图片描述

我已经尝试过相关代码这里,但它不能与地址对齐和对齐结合使用

答案1

嗯,最简单的方法就是将这两个函数移到\patchcmd{\makeletterhead}你的 used 中\renewcommand*{\makeletterhead}就可以得到你所需要的。

使用命令\renewcommand*{\makeletterhead}您可以获得对齐的两个地址(正如您在评论中提到的)。

为了获得合理的文本,只需对所使用的命令进行简单的注释raggedright

% \raggedright% <=======================================================

\textbf{\@title}要添加标题,请在正确的位置添加标题命令:

% \raggedright% <=======================================================
\textbf{\@title}\\[1.5em]% <==========================================
\@opening\\[1.5em]%

使用以下 MWE

\documentclass[12pt,a4paper,sans]{moderncv}

\usepackage[ngerman]{babel}

\usepackage{tabularx}

% moderncv themes
\moderncvstyle{classic}
\moderncvcolor{blue}                             

\setlength{\hintscolumnwidth}{3.3cm} 

% character encoding
\usepackage[utf8]{inputenc}                      
\name{Name}{name}
\title{Lebenslauf}                             
\address{...}{...}
\phone[mobile]{...}                   
\email{Mail}  


 %Should align both adresses on the same "height", justifing and added title
 \makeatletter
\renewcommand*{\makeletterhead}{%
  % recompute lengths (in case we are switching from letter to resume, or vice versa)
  \recomputeletterlengths%
    % recipient block
  \begin{minipage}[t]{.49\textwidth} 
    \raggedright%
    \addressfont%
    {\bfseries\upshape\@recipientname}\\%
    \@recipientaddress%
  \end{minipage}
  % sender contact info
  \hfill%
  \begin{minipage}[t]{.49\textwidth}%
    % optional detailed information
    \if@details%
      \raggedleft%
      \addressfont\textcolor{color2}{%
        {\bfseries\upshape\@firstname~\@lastname}\@firstdetailselementfalse%
        % optional detailed information
        \ifthenelse{\isundefined{\@addressstreet}}{}{\makenewline\addresssymbol\@addressstreet%
          \ifthenelse{\equal{\@addresscity}{}}{}{\makenewline\@addresscity}% if \addresstreet is defined, \addresscity and addresscountry will always be defined but could be empty
          \ifthenelse{\equal{\@addresscountry}{}}{}{\makenewline\@addresscountry}}%
        \collectionloop{phones}{% the key holds the phone type (=symbol command prefix), the item holds the number
          \makenewline\csname\collectionloopkey phonesymbol\endcsname\collectionloopitem}%
        \ifthenelse{\isundefined{\@email}}{}{\makenewline\emailsymbol\emaillink{\@email}}%
        \ifthenelse{\isundefined{\@homepage}}{}{\makenewline\homepagesymbol\httplink{\@homepage}}%
        \ifthenelse{\isundefined{\@extrainfo}}{}{\makenewline\@extrainfo}}\fi%
      \\[1em] % 
      \@date % 
    \end{minipage}\\[2em] 
  % opening
% \raggedright% <=======================================================
  \textbf{\@title}\\[1.5em]% <==========================================
  \@opening\\[1.5em]%
  % ensure no extra spacing after \makelettertitle due to a possible blank line
%  \ignorespacesafterend% not working
  \hspace{0pt}\par\vspace{-\baselineskip}\vspace{-\parskip}}
\makeatother


\begin{document}

\makecvtitle

\section{Foo}

\section{Foo2}
\subsection*{FooFoo}

\clearpage

%-----       letter       ---------------------------------------------------------
% recipient data
\recipient{Company Recruitment team}{Company, Inc.\\123 somestreet\\some city}
\title{Heading should look like this} % <===============================
\date{January 01, 1984}
\opening{Dear Sir or Madam,}
\closing{Yours faithfully,}
\enclosure[Attached]{curriculum vit\ae{}}
\makelettertitle

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ullamcorper 
neque sit amet lectus facilisis sed luctus nisl iaculis. Vivamus at neque 
arcu, sed tempor quam. Curabitur pharetra tincidunt tincidunt. Morbi 
volutpat feugiat mauris, quis tempor neque vehicula volutpat. Duis 
tristique justo vel massa fermentum accumsan. Mauris ante elit, feugiat 
vestibulum tempor eget, eleifend ac ipsum. Donec scelerisque lobortis 
ipsum eu vestibulum. Pellentesque vel massa at felis accumsan rhoncus.

Suspendisse commodo, massa eu congue tincidunt, elit mauris pellentesque 
orci, cursus tempor odio nisl euismod augue. Aliquam adipiscing nibh ut 
odio sodales et pulvinar tortor laoreet. Mauris a accumsan ligula. 
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per 
inceptos himenaeos. Suspendisse vulputate sem vehicula ipsum varius nec 
tempus dui dapibus. Phasellus et est urna, ut auctor erat. Sed tincidunt 
odio id odio aliquam mattis. Donec sapien nulla, feugiat eget adipiscing 
sit amet, lacinia ut dolor. Phasellus tincidunt, leo a fringilla 
consectetur, felis diam aliquam urna, vitae aliquet lectus orci nec 
velit. Vivamus dapibus varius blandit.

Duis sit amet magna ante, at sodales diam. Aenean consectetur porta risus 
et sagittis. Ut interdum, enim varius pellentesque tincidunt, magna 
libero sodales tortor, ut fermentum nunc metus a ante. Vivamus odio leo, 
tincidunt eu luctus ut, sollicitudin sit amet metus. Nunc sed orci 
lectus. Ut sodales magna sed velit volutpat sit amet pulvinar diam 
venenatis.

Albert Einstein discovered that $e=mc^2$ in 1905.

\[ e=\lim_{n \to \infty} \left(1+\frac{1}{n}\right)^n \]


\end{document}

您将获得以下期望结果:

在此处输入图片描述

相关内容