如同这个先前的问题我的,但这次:+a QR code,-itemize
理想情况下,图片、文本和二维码应垂直对齐;文本应水平贴在图像上,二维码应贴在右边距。
这是我目前所做的事情,部分采用了上述问题中的提示:
第一次尝试时,图像和文本对齐得很好,但二维码却没有对齐,无论是垂直对齐还是水平对齐。第二次尝试时,图像和二维码垂直对齐,但文本却没有对齐,二维码再次出现Overfull \hbox
。
\documentclass[a4paper, 10pt]{scrartcl}
\usepackage[american]{babel}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[a4paper, left=12.7mm, right=12.7mm, top=12.7mm, bottom=13mm]{geometry}
\usepackage{showframe}
\usepackage{tabu, booktabs}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{qrcode}
\newlength\threeLines
\setlength{\threeLines}{12mm}
\begin{document}
\sffamily
\tabulinesep=0pt
\extrarowsep=0pt
\begin{tabu}{@{} X[l,1] X[l,18] X[r,1] @{}}
\includegraphics[width=\threeLines, height=\threeLines, valign=t]{example-image} &
{This text spans \par
Over Three Lines and \par
Should be close to the image} &
\qrcode[height=\threeLines]{https://tex.stackexchange.com/questions/289863/how-to-get-rid-of-vertical-offset-in-a-table-containing-pictures} \\
\end{tabu}
\vspace*{24pt}
\begin{tabu}{@{} X[l,1] X[l,18] X[r,1] @{}}
\toprule
\raisebox{-\height}[0pt][1.1\height]{\includegraphics[width=\threeLines, height=\threeLines, valign=t]{example-image}} &
{This text spans \par
Over Three Lines and \par
Should be close to the image} &
\raisebox{-\height}[0pt][1.1\height]{\qrcode[height=\threeLines]{https://tex.stackexchange.com/questions/289863/how-to-get-rid-of-vertical-offset-in-a-table-containing-pictures}} \\
\end{tabu}
\end{document}
对我来说,手动将列宽比例设置为也显得很笨拙18
,但否则图像和文本之间的水平距离会变得太大。
所以我的问题是:如何正确对齐这三个元素?有什么比这更好的吗tabu(lar)
?如果可能的话,我想避免使用 TikZ。
答案1
您可以使用基于\parbox
和组合的解决方案\adjustbox
,以更好地提高垂直对齐。
\documentclass[a4paper, 10pt]{scrartcl}
\usepackage[american]{babel}
\usepackage{lmodern}
\usepackage[a4paper, left=12.7mm, right=12.7mm, top=12.7mm, bottom=13mm]{geometry}
\usepackage{showframe}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{qrcode}
\newlength\threeLines
\setlength{\threeLines}{12mm}
\begin{document}
\noindent
\includegraphics[width=\threeLines, height=\threeLines, valign=t]{example-image}%
\adjustbox{valign=t}{\parbox[t]{5cm}{This text spans\\
Over Three Lines and\\
Should be close to the image}}\hfill
\adjustbox{valign=t}{\qrcode[height=\threeLines]{http://tex.stackexchange.com/questions/289863/how-to-get-rid-of-vertical-offset-in-a-table-containing-pictures}}
\vspace*{24pt}\hrule\vspace*{5pt}
\noindent
\includegraphics[width=\threeLines, height=\threeLines, valign=t]{example-image}%
\adjustbox{valign=t}{\parbox[t]{5cm}{This text spans\\
Over Three Lines and\\
Should be close to the image}}\hfill
\adjustbox{valign=t}{\qrcode[height=\threeLines]{http://tex.stackexchange.com/questions/289863/how-to-get-rid-of-vertical-offset-in-a-table-containing-pictures}}
\end{document}
答案2
该表在这里似乎没有什么用处所以我将其删除了。
\documentclass[a4paper, 10pt]{scrartcl}
\usepackage[american]{babel}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[a4paper, left=12.7mm, right=12.7mm, top=12.7mm, bottom=13mm]{geometry}
\usepackage{showframe}
\usepackage{tabu, booktabs}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{qrcode}
\newlength\threeLines
\setlength{\threeLines}{12mm}
\begin{document}
\sffamily
\noindent
\includegraphics[width=\threeLines, height=\threeLines]{example-image}%
\parbox[b]{5cm}{This text spans\\
Over Three Lines and\\
Should be close to the image}\hfill
\raisebox{\depth}{\qrcode[height=\threeLines,tight]{http://tex.stackexchange.com/questions/289863/how-to-get-rid-of-vertical-offset-in-a-table-containing-pictures}}
\vspace*{24pt}
\hrule
\vspace*{5pt}
\noindent
\includegraphics[width=\threeLines, height=\threeLines]{example-image}%
\parbox[b]{5cm}{This text spans\\
Over Three Lines and\\
Should be close to the image}\hfill
\raisebox{\depth}{\qrcode[height=\threeLines]{http://tex.stackexchange.com/questions/289863/how-to-get-rid-of-vertical-offset-in-a-table-containing-pictures}}
\end{document}
答案3
和“纯”tabu
解决方案(使用正确的tabu
语法):
\documentclass[a4paper, 10pt]{scrartcl}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[a4paper, left=12.7mm, right=12.7mm, top=12.7mm, bottom=13mm]{geometry}
\usepackage{booktabs, tabu}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{qrcode}
\newlength\threeLines
\setlength{\threeLines}{12mm}
\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}
\begin{document}
\sffamily
\centering%
\setlength\tabcolsep{2pt}
\begin{tabu} to \linewidth {@{} m{\threeLines} X[l, m] m{\threeLines} @{}}
\includegraphics[width=\threeLines, height=\threeLines]{example-image}
&
This text spans \par
Over Three Lines and \par
Should be close to the image
&
\qrcode[height=\threeLines]{http://tex.stackexchange.com/questions/289863/how-to-get-rid-of-vertical-offset-in-a-table-containing-pictures}
\end{tabu}
\vspace*{24pt}
\begin{tabu} to \linewidth {@{} m{\threeLines} X[l, m] m{\threeLines} @{}}
\toprule
\includegraphics[width=\threeLines, height=\threeLines]{example-image}
&
This text spans \par
Over Three Lines and \par
Should be close to the image
&
\qrcode[height=\threeLines]{http://tex.stackexchange.com/questions/289863/how-to-get-rid-of-vertical-offset-in-a-table-containing-pictures}
\end{tabu}
\end{document}