将 newcommand 的拆分参数放入跨多行的多列元素中

将 newcommand 的拆分参数放入跨多行的多列元素中

我修改了来自 CV 模板的以下功能:

\newcommand{\ressubheading}[4]{
\begin{tabularx}{6in}{l@{\cftdotfill{\cftsecdotsep}\extracolsep{\fill}}r}
        \textbf{#1} & #2 \\
        \textit{#3} & \textit{#4} \\
\end{tabularx}\vspace{2pt}}

进入:

\newcommand{\ressubheading2}[5]{
\begin{tabularx}{6in}{l@{\cftdotfill{\cftsecdotsep}\extracolsep{\fill}}r}
        \textbf{#1} & #2 \\
        \textit{#3} & \textit{#4} \\
        \multicolumn{2}{l}{\setlength{\parindent}{4ex}\indent \textbf{Report}: \makecell{{#5}}}
\end{tabularx}\vspace{2pt}}

接受额外的输入参数。修改后的参数可以这样使用:

\ressubheading2{MyUniversity}{Country }{Course of Studies}{from - to}{Final report}

当文档中有多个此类条目时,这两个函数都允许对齐它们。如果表示输入 5 的字符串足够短,则一切正常。但是,如果字符串太长,条目将不再对齐。我尝试使用以下内容拆分最后一个条目\newline

\ressubheading2{MyUniversity}{Country }{Course of Studies}{from - to}{Very, extremely long final report title \newline that misaligns everything}

但这不起作用。

\multicolumn{}我怎样才能分割进入元素的线tabularx以保持对齐?

完整工作示例

这里有一个例子可以更好地说明我的意思。

\documentclass[letterpaper,11pt]{article}
\newlength{\outerbordwidth}
\pagestyle{empty}
\raggedbottom
\raggedright
\usepackage[svgnames]{xcolor}
\usepackage{framed}
\usepackage{tocloft}
\usepackage{makecell, tabularx}
\usepackage{multicol}
\usepackage[hidelinks]{hyperref}
\usepackage[explicit]{titlesec}
\usepackage{natbib}
\usepackage{bibentry}

\setlength{\outerbordwidth}{3pt}  % Width of border outside of title bars
\definecolor{shadecolor}{gray}{0.75}  % Outer background color of title bars (0 = black, 1 = white)
\definecolor{shadecolorB}{gray}{0.93}  % Inner background color of title bars

\setlength{\evensidemargin}{-0.25in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\oddsidemargin}{-0.25in}
\setlength{\paperheight}{11in}
\setlength{\paperwidth}{8.5in}
\setlength{\tabcolsep}{0in}
\setlength{\textheight}{9.5in}
\setlength{\textwidth}{7in}
\setlength{\topmargin}{-0.3in}
\setlength{\topskip}{0in}
\setlength{\voffset}{0.1in}



\newcommand{\ressubheading}[4]{
\begin{tabularx}{6in}{l@{\cftdotfill{\cftsecdotsep}\extracolsep{\fill}}r}
        \textbf{#1} & #2 \\
        \textit{#3} & \textit{#4} \\
\end{tabularx}\vspace{2pt}}

\newcommand{\ressubheadingNew}[5]{
\begin{tabularx}{6in}{l@{\cftdotfill{\cftsecdotsep}\extracolsep{\fill}}r}
        \textbf{#1} & #2 \\
        \textit{#3} & \textit{#4} \\
        \multicolumn{2}{l}{\setlength{\parindent}{4ex}\indent \textbf{Thesis}: \makecell{{#5}}}
\end{tabularx}\vspace{2pt}}
%-----------------------------------------------------------

\begin{document}


\begin{tabularx}{7in}{l@{\extracolsep{\fill}}r}
\textbf{\Huge MyName} \\
[email protected] & Mobile: 018923123890123890123890 \\
 & \\
\end{tabularx}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%SECTION%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Education}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \ressubheadingNew{University of Neverland}{Neverland}{Bachelor studies in Flight}{September 2020 - October 2020}{Development of flight}
    \ressubheadingNew{University of Neverland}{Neverland}{Master studies in Flight}{October 2020 - November 2020}{Development of swimming skills}
        \ressubheadingNew{University of Neverland}{Neverland}{Postgraduate studies in Flight}{October 2020 - November 2020}{Very long title that should be split across lines but that does not even when using newline}    
\end{document}

输出结果如下 在此处输入图片描述

答案1

  • 对于命令定义中的最后一项,\ressubheadingNew您可以使用\makecell命令。它不会自动中断其内容,因此您需要通过在适当的位置插入 ` \ 来手动中断它。
  • 在定义中,\ressubheadingNew您有makcell一对过多的花括号。它应该如下:
\newcommand{\ressubheadingNew}[5]{
\begin{tabularx}{6in}{l@{\cftdotfill{\cftsecdotsep}\extracolsep{\fill}}r}
        \textbf{#1} & #2 \\
        \textit{#3} & \textit{#4} \\
        \multicolumn{2}{l}{\setlength{\parindent}{4ex}\indent \textbf{Thesis}:% 
        \makecell[t]{#5}}  % <--- aded [t] and remove one pair of {}
\end{tabularx}\vspace{2pt}}

使用 MWE 进行测试:

\documentclass[letterpaper,11pt]{article}
\newlength{\outerbordwidth}
\pagestyle{empty}
\raggedbottom
\raggedright
\usepackage[svgnames]{xcolor}
\usepackage{framed}
\usepackage{tocloft}
\usepackage{makecell, tabularx}
\usepackage{multicol}
\usepackage[explicit]{titlesec}
\usepackage{natbib}
\usepackage{bibentry}
\usepackage[hidelinks]{hyperref} % should be loaded last in preamble

\setlength{\outerbordwidth}{3pt}  % Width of border outside of title bars
\definecolor{shadecolor}{gray}{0.75}  % Outer background color of title bars (0 = black, 1 = white)
\definecolor{shadecolorB}{gray}{0.93}  % Inner background color of title bars

\setlength{\evensidemargin}{-0.25in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\oddsidemargin}{-0.25in}
\setlength{\paperheight}{11in}
\setlength{\paperwidth}{8.5in}
\setlength{\tabcolsep}{0in}
\setlength{\textheight}{9.5in}
\setlength{\textwidth}{7in}
\setlength{\topmargin}{-0.3in}
\setlength{\topskip}{0in}
\setlength{\voffset}{0.1in}



\newcommand{\ressubheading}[4]{
\begin{tabularx}{6in}{l@{\cftdotfill{\cftsecdotsep}\extracolsep{\fill}}r}
        \textbf{#1} & #2 \\
        \textit{#3} & \textit{#4} \\
\end{tabularx}\vspace{2pt}}

\newcommand{\ressubheadingNew}[5]{
\begin{tabularx}{6in}{l@{\cftdotfill{\cftsecdotsep}\extracolsep{\fill}}r}
        \textbf{#1} & #2 \\
        \textit{#3} & \textit{#4} \\
        \multicolumn{2}{l}{\setlength{\parindent}{4ex}\indent \textbf{Thesis}:% 
        \makecell[t]{#5}}
\end{tabularx}\vspace{2pt}}
%-----------------------------------------------------------

\begin{document}


\begin{tabularx}{7in}{l@{\extracolsep{\fill}}r}
\textbf{\Huge MyName} \\
[email protected] & Mobile: 018923123890123890123890 \\
 & \\
\end{tabularx}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Education}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \ressubheadingNew{University of Neverland}{Neverland}{Bachelor studies in Flight}{September 2020 - October 2020}{Development of flight}
    \ressubheadingNew{University of Neverland}{Neverland}{Master studies in Flight}{October 2020 - November 2020}{Development of swimming skills}
        \ressubheadingNew{University of Neverland}{Neverland}{Postgraduate studies in Flight}{October 2020 - November 2020}{Very long title that should be split\\ across lines but that does not even\\ when using newline}
\end{document}

在此处输入图片描述

答案2

我建议不要使用表格,而只是格式化一个段落,例如如下所示。

\newcommand\ressubheadingNew[5]{%
   \par\medskip\noindent
   \textbf{#1}\hfill #2\\
   \textit{#3}\hfill\textit{#4}\\
   \hspace*{4ex}\parbox[t]{\dimexpr\textwidth-4ex}{\textbf{Thesis:} #5}%
}

最后一行说明您可以使用\parboxes来限制文本。这种方法还有一个优点,就是它可以跨页面拆分。

在此处输入图片描述

\newlength{\outerbordwidth}
\pagestyle{empty}
\raggedbottom
\raggedright
\usepackage[svgnames]{xcolor}
\usepackage{framed}
\usepackage{tocloft}
\usepackage{makecell, tabularx}
\usepackage{multicol}
\usepackage[hidelinks]{hyperref}
\usepackage[explicit]{titlesec}
\usepackage{natbib}
\usepackage{bibentry}

\setlength{\outerbordwidth}{3pt}  % Width of border outside of title bars
\definecolor{shadecolor}{gray}{0.75}  % Outer background color of title bars (0 = black, 1 = white)
\definecolor{shadecolorB}{gray}{0.93}  % Inner background color of title bars

\setlength{\evensidemargin}{-0.25in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\oddsidemargin}{-0.25in}
\setlength{\paperheight}{11in}
\setlength{\paperwidth}{8.5in}
\setlength{\tabcolsep}{0in}
\setlength{\textheight}{9.5in}
\setlength{\textwidth}{7in}
\setlength{\topmargin}{-0.3in}
\setlength{\topskip}{0in}
\setlength{\voffset}{0.1in}



\newcommand{\ressubheading}[4]{
\begin{tabularx}{6in}{l@{\cftdotfill{\cftsecdotsep}\extracolsep{\fill}}r}
        \textbf{#1} & #2 \\
        \textit{#3} & \textit{#4} \\
\end{tabularx}\vspace{2pt}}

% \newcommand{\ressubheadingNew}[5]{
% \begin{tabularx}{6in}{l@{\cftdotfill{\cftsecdotsep}\extracolsep{\fill}}r}
%         \textbf{#1} & #2 \\
%         \textit{#3} & \textit{#4} \\
%         \multicolumn{2}{l}{\setlength{\parindent}{4ex}\indent \textbf{Thesis}: \makecell{{#5}}}
% \end{tabularx}\vspace{2pt}}
%-----------------------------------------------------------

\newcommand\ressubheadingNew[5]{%
\par\medskip\noindent
\textbf{#1}\hfill #2\\
\textit{#3}\hfill\textit{#4}\\
\hspace*{4ex}\parbox[t]{\dimexpr\textwidth-4ex}{\textbf{Thesis:} #5}%
}


\begin{document}


\begin{tabularx}{7in}{l@{\extracolsep{\fill}}r}
\textbf{\Huge MyName} \\
[email protected] & Mobile: 018923123890123890123890 \\
 & \\
\end{tabularx}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%SECTION%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Education}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \ressubheadingNew{University of Neverland}{Neverland}{Bachelor studies in Flight}{September 2020 - October 2020}{Development of flight}
    \ressubheadingNew{University of Neverland}{Neverland}{Master studies in Flight}{October 2020 - November 2020}{Development of swimming skills}
    \ressubheadingNew{University of Neverland}{Neverland}{Postgraduate studies in Flight}{October 2020 - November 2020}{Very long title that should be split using newline like here\\
    but which also splits automatically if it is long enough and goes on and goes on and goes on and goes on and goes on and goes on and goes on}    
  \ressubheadingNew{University of Neverland}{Neverland}%
  {\parbox[t]{0.5\textwidth}{This illustrates an emergency if the title of the master programme is really long}}{October 2020 - November 2020}{Development of swimming skills}
\end{document}

答案3

采取的解决方案从这个答案

\newcommand{\ressubheadingNew}[5]{
\begin{tabularx}{\linewidth}{l@{\cftdotfill{\cftsecdotsep}\extracolsep{\fill}}r}
        \textbf{#1} & #2 \\
        \textit{#3} & \textit{#4} \\
        \multicolumn{2}{{p{\dimexpr\linewidth-2\tabcolsep-2\arrayrulewidth}}}{\setlength{\parindent}{4ex}\indent \textbf{Thesis}: {#5}}\\
\end{tabularx}\vspace{2pt}}

相关内容