这在某种程度上是表格单元格内的换行行距问题。
我想要做的是在一个表格单元格中使用不同的字体样式。到目前为止,我了解到局部大小更改{\small this is a small style\par}
应始终以 结束,\par
以便行距 ( \baselineskip
) 得到很好的调整。到目前为止一切顺利。这按预期工作,每个\par
都会换行并调整行距。问题是,\par
表格单元格中的最后一个会向文本添加换行符,而在本例中这是不需要的。
我的问题是,是否存在另一个 latex 命令,它具有与\par
行距相同的效果,但不添加换行符?或者有其他解决方法,我们将不胜感激!
这是一个小例子(它主要基于我上一篇文章中的代码):
\documentclass[11pt,paper=a4,11pt,parskip=half,draft]{scrartcl}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{longtable}
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{xcolor}
\usepackage{ifthen}
\usepackage{blindtext}
\definecolor{darkblue}{HTML}{212650}
% https://tex.stackexchange.com/a/218826/46403
\newcommand{\cvitemdate}[1]{\sffamily #1}
\newcommand{\cvitemhead}[1]{\sffamily\textcolor{darkblue}{\bfseries #1}}
\newcommand{\cvitemplace}[1]{\sffamily\itshape\footnotesize #1}
\newcommand{\cviteminfo}[1]{\scriptsize #1}
% formating info text
\newcommand{\cvitem}[5]{%
% 1st column
{\cvitemdate{#1}} &%
% 2nd column - first textline
{\cvitemhead{#2}\par}%
% 2nd column - second textline
\ifthenelse{\equal{#3}{}}{}{%
{\cvitemplace{#3}\par}%
}%
\ifthenelse{\equal{#5}{}}{\vspace{6pt}}{\vspace{3pt}}%
% 2nd column - third textline
\ifthenelse{\equal{#4}{}}{}{%
{\cviteminfo{#4}\par}%
}%
\ifthenelse{\equal{#5}{}}{}{\vspace{3pt}}%
% 2nd column - fourth textline
\ifdefined\isfull%
\ifthenelse{\equal{#5}{}}{}{%
{\cviteminfo{#5}\par}%
}%
\else\fi%
%\vspace*{-\baselineskip}
\tabularnewline%
}
% https://tex.stackexchange.com/a/7348/46403
% ragged2e packages provides text hyphenation in columns
\newcolumntype{L}[1]{>{\raggedright\hspace{0pt}\arraybackslash}p{#1}} % left with dimension
\newcommand{\colwidth}[1]{%
\dimexpr #1\textwidth-2\tabcolsep%
}%
\begin{document}
\begin{longtable}[!htbp]{|@{}L{\colwidth{0.2}}|L{\colwidth{0.8}}@{}|}
\hline
\cvitem{Itemdate 1}
{Itemhead 1}
{Itemplace 1}
{\textbf{Iteminfo 1.1}: \blindtext[1]}
{\textbf{Iteminfo 1.2}: \blindtext[1]}
\hline
\cvitem{Itemdate 2}
{Itemhead 2}
{Itemplace 2}
{}
{}
\hline
\cvitem{Itemdate 3}
{Itemhead 3}
{}
{}
{}
\hline
\end{longtable}
\end{document}
答案1
你想要这样的东西吗?
我已将您的定义替换为\cvitem
以下定义:
\newcommand{\cvitem}[5]{%
{\cvitemdate{#1}} &%
{\cvitemhead{#2}\par}
\ifthenelse{\equal{#3}{}}%
{\vspace*{-\baselineskip}}%
{{\cvitemplace{#3}\par}
\ifthenelse{\equal{#4}{}}%
{\vspace*{-\baselineskip}}%
{{\vspace{6pt}\cviteminfo{#4}\par}
\ifthenelse{\equal{#5}{}}%
{}%
{\ifdefined\isfull\vspace{3pt}{\cviteminfo{#5}\par}\fi%
}%
\vspace*{-\baselineskip}%
}%
}%
\vspace*{-\baselineskip}%
\tabularnewline%
}
完成 MWE:
\documentclass[11pt,paper=a4,11pt,parskip=half,draft]{scrartcl}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{longtable}
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{xcolor}
\usepackage{ifthen}
\usepackage{blindtext}
\definecolor{darkblue}{HTML}{212650}
\newcommand\isfull
% http://tex.stackexchange.com/a/218826/46403
\newcommand{\cvitemdate}[1]{\sffamily #1}
\newcommand{\cvitemhead}[1]{\sffamily\textcolor{darkblue}{\bfseries #1}}
\newcommand{\cvitemplace}[1]{\sffamily\itshape\footnotesize #1}
\newcommand{\cviteminfo}[1]{\scriptsize #1}
% formatting info text
\newcommand{\cvitem}[5]{%
{\cvitemdate{#1}} &%
{\cvitemhead{#2}\par}
\ifthenelse{\equal{#3}{}}%
{\vspace*{-\baselineskip}}%
{{\cvitemplace{#3}\par}
\ifthenelse{\equal{#4}{}}%
{\vspace*{-\baselineskip}}%
{{\vspace{6pt}\cviteminfo{#4}\par}
\ifthenelse{\equal{#5}{}}%
{}%
{\ifdefined\isfull\vspace{3pt}{\cviteminfo{#5}\par}\fi%
}%
\vspace*{-\baselineskip}%
}%
}%
\vspace*{-\baselineskip}%
\tabularnewline%
}
% http://tex.stackexchange.com/a/7348/46403
% ragged2e packages provides text hyphenation in columns
\newcolumntype{L}[1]{>{\raggedright\hspace{0pt}\arraybackslash}p{#1}} % left with dimension
\newcommand{\colwidth}[1]{%
\dimexpr #1\textwidth-2\tabcolsep%
}%
\begin{document}
\begin{longtable}[!htbp]{|@{}L{\colwidth{0.2}}|L{\colwidth{0.8}}@{}|}
\hline
\cvitem{Itemdate 1}
{Itemhead 1}
{Itemplace 1}
{\textbf{Iteminfo 1.1}: \blindtext[1]}
{\textbf{Iteminfo 1.2}: \blindtext[1]}
\hline
\cvitem{Itemdate 2}
{Itemhead 2}
{Itemplace 2}
{\textbf{Iteminfo 2.1}: \blindtext[1]}
{}
\hline
\cvitem{Itemdate 3}
{Itemhead 3}
{Itemplace 3}
{}
{}
\hline
\cvitem{Itemdate 4}
{Itemhead 4}
{}
{}
{}
\hline
\end{longtable}
\end{document}
编辑
如果第三、第四和第五个参数之间可以为空,则将上述代码替换为:
\newcommand{\cvitem}[5]{%
{\cvitemdate{#1}} &%
{\cvitemhead{#2}\par}
\ifthenelse{\equal{#3}{}}
{}
{{\cvitemplace{#3}\par}}%
\ifthenelse{\equal{#4}{}}
{}
{{\vspace{6pt}\cviteminfo{#4}\par}}%
\ifthenelse{\equal{#5}{}}%
{}%
{\ifdefined\isfull\vspace{3pt}{\cviteminfo{#5}\par}\fi}%
\vspace*{-\baselineskip}%
\vspace*{-\baselineskip}%
\tabularnewline%
}