在尝试撰写某种“通缉海报”时(斯特克布里夫),我无法消除 LaTeX 自动引入的垂直间距!这是一个 MWE,它应该可以在--shell-escape
启用的 Linux/Mac OS 上工作,尽管我需要运行它两次。我选择了这个变体,因为我不想,甚至无法上传个人照片。
% arara: pdflatex: {shell: yes}
% arara: pdflatex: {synctex: yes}
%% MWE to show a problem with pictures and text in tabu
\documentclass[paper=a4, oneside, fontsize=12pt]{scrartcl}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[ngerman, english]{babel}
\parindent3mm
%% page geometry
\usepackage[a4paper, left=30mm, right=30mm,
top=25mm, bottom=30mm]{geometry}
%% Selection of the fonts
\usepackage{bookman}
\usepackage[final]{microtype}
\overfullrule=1mm
%% to get 1.5 line spacing (Actually 1.25)
\usepackage{setspace}
\onehalfspacing
\setlength{\parindent}{5mm}
%% For the tables!
\usepackage{tabu, longtable, booktabs}
%\usepackage{multirow}
\usepackage{graphicx}
\begin{document}
\title{MWE to show a problem with pictures and text in tabu}
\author{rotton}
\date{\today}
\maketitle
%% load the pictures from the web, if necessary
\IfFileExists{./DonEK.jpg}
{}
{
\write18{wget -O ./DonEK.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/KnuthAtOpenContentAlliance.jpg/406px-KnuthAtOpenContentAlliance.jpg?download}
}
\IfFileExists{./LeslieL.jpg}
{}
{
\write18{wget -O ./LeslieL.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Leslie_Lamport.jpg/377px-Leslie_Lamport.jpg?download}
}
%% Construction of the table itself
\tabulinesep=2pt
\extrarowsep=2pt
\begin{tabu}{X[c] X[2,l] X[2,l]} %% 3 columns, width ratio 1:2:2
\toprule
\includegraphics[width=0.16\textwidth]{DonEK} Donald E. Knuth &
%\vspace{-6em}
\underline{Deutsch}
\begin{itemize}
\item Erfinder \textit{(und etwas mehr Text)}
\item von
\item \TeX
\end{itemize} &
\underline{English}
\begin{itemize}
\item Inventor \textit{(and some more text)}
\item of
\item \TeX
\end{itemize} \\
\midrule
\includegraphics[width=0.16\textwidth]{LeslieL} Leslie Lamport &
\underline{Deutsch}
\begin{itemize}
\item veröffentlichte Makros und Hilfsprogramme zum einfachen Umgang mit \TeX
\item ==> \LaTeX
\end{itemize} &
\underline{English}
\begin{itemize}
\item published macros and auxiliary programs for easy handling of \TeX
\item ==> \LaTeX
\end{itemize} \\
\bottomrule
\end{tabu}
\end{document}
如您所见,与照片相比,第二列和第三列的文本之间存在较大的垂直偏移。我手动添加了一些红色箭头来突出显示这一点。如何摆脱那个空间?我知道我可以手动引入负垂直空间(第 58 行,注释掉),但这对我来说似乎非常不合技术!(另一种方法是使用 TikZ,但这真的是另一个故事。)
答案1
添加\usepackage[export]{adjustbox}
并使用
\includegraphics[width=0.16\textwidth,valign=t]{DonEK}
例子:
\documentclass[paper=a4, oneside, fontsize=12pt]{scrartcl}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[ngerman, english]{babel}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\parindent3mm
%% page geometry
\usepackage[a4paper, left=30mm, right=30mm,
top=25mm, bottom=30mm]{geometry}
%% Selection of the fonts
\usepackage{bookman}
\usepackage[final]{microtype}
\overfullrule=1mm
%% to get 1.5 line spacing (Actually 1.25)
\usepackage{setspace}
\onehalfspacing
\setlength{\parindent}{5mm}
%% For the tables!
\usepackage{tabu, longtable, booktabs}
%\usepackage{multirow}
\begin{document}
\title{MWE to show a problem with pictures and text in tabu}
\author{rotton}
\date{\today}
\maketitle
%% load the pictures from the web, if necessary
\IfFileExists{./DonEK.jpg}
{}
{
\write18{wget -O ./DonEK.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/KnuthAtOpenContentAlliance.jpg/406px-KnuthAtOpenContentAlliance.jpg?download}
}
\IfFileExists{./LeslieL.jpg}
{}
{
\write18{wget -O ./LeslieL.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Leslie_Lamport.jpg/377px-Leslie_Lamport.jpg?download}
}
%% Construction of the table itself
\tabulinesep=2pt
\extrarowsep=2pt
\begin{tabu}{X[c] X[2,l] X[2,l]} %% 3 columns, width ratio 1:2:2
\toprule
\includegraphics[width=0.16\textwidth,valign=t]{DonEK} Donald E. Knuth &
%\vspace{-6em}
\underline{Deutsch}
\begin{itemize}
\item Erfinder \textit{(und etwas mehr Text)}
\item von
\item \TeX
\end{itemize} &
\underline{English}
\begin{itemize}
\item Inventor \textit{(and some more text)}
\item of
\item \TeX
\end{itemize} \\
\midrule
\includegraphics[width=0.16\textwidth,valign=t]{LeslieL} Leslie Lamport &
\underline{Deutsch}
\begin{itemize}
\item veröffentlichte Makros und Hilfsprogramme zum einfachen Umgang mit \TeX
\item ==> \LaTeX
\end{itemize} &
\underline{English}
\begin{itemize}
\item published macros and auxiliary programs for easy handling of \TeX
\item ==> \LaTeX
\end{itemize} \\
\bottomrule
\end{tabu}
\end{document}
答案2
您可以使用一个简单的\raisebox
命令来完成此操作:
\documentclass[paper=a4, oneside, fontsize=12pt]{scrartcl}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[ngerman, english]{babel}
\parindent3mm
%% page geometry
\usepackage[a4paper, left=30mm, right=30mm,
top=25mm, bottom=30mm]{geometry}
%% Selection of the fonts
\usepackage{bookman}
\usepackage[final]{microtype}
\overfullrule=1mm
%% to get 1.5 line spacing (Actually 1.25)
\usepackage{setspace}
\onehalfspacing
\setlength{\parindent}{5mm}
%% For the tables!
\usepackage{tabu, longtable, booktabs}
%\usepackage{multirow}
\usepackage[demo]{graphicx}
\usepackage{multirow, makecell}
\begin{document}
\title{MWE to show a problem with pictures and text in tabu}
\author{rotton}
\date{\today}
\maketitle
%% load the pictures from the web, if necessary
\IfFileExists{./DonEK.jpg}
{}
{
\write18{wget -O ./DonEK.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/KnuthAtOpenContentAlliance.jpg/406px-KnuthAtOpenContentAlliance.jpg?download}
}
\IfFileExists{./LeslieL.jpg}
{}
{
\write18{wget -O ./LeslieL.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Leslie_Lamport.jpg/377px-Leslie_Lamport.jpg?download}
}
%% Construction of the table itself
\tabulinesep=2pt
\extrarowsep=2pt
\begin{tabu}{X[c] X[2,l] X[2,l]} %% 3 columns, width ratio 1:2:2
\toprule
\raisebox{-\height}[0pt][1.1\height]{\includegraphics[width=0.16\textwidth]{DonEK}} Donald E. Knuth &
%\vspace{-6em}
\underline{Deutsch}
\begin{itemize}
\item Erfinder \textit{(und etwas mehr Text)}
\item von
\item \TeX
\end{itemize} &
\underline{English}
\begin{itemize}
\item Inventor \textit{(and some more text)}
\item of
\item \TeX
\end{itemize} \\
\midrule
\raisebox{-\height}[0pt][1.1\height]{\includegraphics[width=0.16\textwidth]{LeslieL}} Leslie Lamport &
\underline{Deutsch}
\begin{itemize}
\item veröffentlichte Makros und Hilfsprogramme zum einfachen Umgang mit \TeX
\item ==> \LaTeX
\end{itemize} &
\underline{English}
\begin{itemize}
\item published macros and auxiliary programs for easy handling of \TeX
\item ==> \LaTeX
\end{itemize} \\
\bottomrule
\end{tabu}
\end{document}
答案3
虽然提供的答案通常都有效,但我最终还是使用了 TikZ,因为它具有更大的灵活性。命令中看起来有些复杂的部分\mycasenode
是使文本顶部对齐所必需的。以下是代码:
% arara: pdflatex: {shell: yes}
% arara: pdflatex: {synctex: yes}
%% MWE to show an alternative solution for a problem with pictures and text in tabu
\documentclass\[paper=a4, oneside, fontsize=12pt\]{scrartcl}
%% da Bericht auf Deutsch:
\usepackage\[utf8\]{inputenx}
\usepackage\[T1\]{fontenc}
\usepackage{textcomp}
\usepackage\[ngerman\]{babel}
%% page geometry
\usepackage\[a4paper, left=30mm, right=30mm,
top=20mm, bottom=30mm\]{geometry}
%\usepackage{showframe}
%% Selection of the fonts
\usepackage{bookman}
\usepackage\[final\]{microtype}
\overfullrule=1mm
%% to get 1.5 line spacing (Actually 1.25)
\usepackage{setspace}
\onehalfspacing
\parindent0mm
%% For the tables!
\usepackage{tabu, longtable, booktabs}
%\usepackage{multirow}
\usepackage{graphicx}
\usepackage\[export\]{adjustbox}
%% for the whole Tikz stuff
\usepackage{multicol}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart, shapes.misc, matrix, positioning}
\tikzstyle{fotobox}=\[
rectangle, rounded corners=1mm,
draw=black, very thick,
text centered, text width=\textwidth*1/5\]
\tikzstyle{textbox}=\[
rectangle, rounded corners=1mm,
draw=black, very thick,
text width=\textwidth*2/5-8mm\]
\tikzstyle{textbox2}=\[
rectangle, rounded corners=1mm,
draw=black, very thick,
text width=\textwidth*2/5-6mm,
append after command={node\[anchor=north west, minimum height=5mm, text width=\textwidth*2/5-6mm\]
at (\tikzlastnode.north west){#1}}\]
\def\mycasenode(#1)\[#2\]#3;{\node (#1) \[textbox2={#3}, #2\] {};}
\newcommand*{\knuthDe}{
\underline{Deutsch}
\begin{itemize}
\item Erfinder \textit{(und etwas mehr Text)}
\item von
\item \TeX
\item TW: \the\textwidth
\end{itemize}
}
\newcommand*{\knuthEng}{
\underline{English}
\begin{itemize}
\item Inventor \textit{(and some more text)}
\item of
\item \TeX
\end{itemize}
}
\newcommand*{\lamportDe}{
\underline{Deutsch}
\begin{itemize}
\item veröffentlichte Makros und Hilfsprogramme zum einfachen Umgang mit \TeX
\item $\Longrightarrow$ \LaTeX
%\item Erhielt 2013 den Turing Award für seine Beiträge zur Theorie und Praxis verteilter und nebenläufiger Systeme
\end{itemize}
}
\newcommand*{\lamportEng}{
\underline{English}
\begin{itemize}
\item published macros and auxiliary programs for easy handling of \TeX
\item $\Longrightarrow$ \LaTeX
\end{itemize}
}
\begin{document}
\title{An alternative solution (using TikZ) for a problem with pictures and text in tabu}
\author{rotton}
\date{\today}
\maketitle
%% load the pictures from the web, if necessary
\IfFileExists{./DonEK.jpg}
{}
{
\write18{wget -O ./DonEK.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/KnuthAtOpenContentAlliance.jpg/406px-KnuthAtOpenContentAlliance.jpg?download}
}
\IfFileExists{./LeslieL.jpg}
{}
{
\write18{wget -O ./LeslieL.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Leslie_Lamport.jpg/377px-Leslie_Lamport.jpg?download}
}
%% Don E Knuth
\begin{tikzpicture}\[minimum height=55mm, node distance=5mm and 5mm\]
\node(bild1)\[fotobox, \] at (0,0)
{\includegraphics\[width=30mm\]{DonEK} \\ Donald E.\ Knuth};
%\node(knuthDe)\[textbox, text width=\textwidth-53mm, right=1mm of bild1.north east, anchor=north west\]{\knuthDe};
\mycasenode(knuthDe)\[right=1mm of bild1.north east, anchor=north west\]{\knuthDe};
\mycasenode()\[right=1mm of knuthDe.north east, anchor=north west\]{\knuthEng};
%\node()\[textbox, right=1mm of bende.north east, anchor=north west\]{\knuthEng};
%\end{tikzpicture}
%
%% Leslie Lamport
%\begin{tikzpicture}\[minimum height=55mm, node distance=0mm and 5mm\]
\node(bild2)\[fotobox, below=of bild1.south west, anchor=north west\]
{\includegraphics\[width=30mm\]{LeslieL} \\ Leslie Lamport};
\mycasenode(lamportDe)\[right=1mm of bild2.north east, anchor=north west\]{\lamportDe};
\mycasenode()\[right=1mm of lamportDe.north east, anchor=north west\]{\lamportEng};
\end{tikzpicture}
\end{document}