![如何将图形和文本对齐到小页面的垂直中心?](https://linux22.com/image/361876/%E5%A6%82%E4%BD%95%E5%B0%86%E5%9B%BE%E5%BD%A2%E5%92%8C%E6%96%87%E6%9C%AC%E5%AF%B9%E9%BD%90%E5%88%B0%E5%B0%8F%E9%A1%B5%E9%9D%A2%E7%9A%84%E5%9E%82%E7%9B%B4%E4%B8%AD%E5%BF%83%EF%BC%9F.png)
\documentclass[10pt,UTF8]{ctexbook}
\usepackage{xcolor}
\usepackage{varwidth}
\usepackage{graphicx}
\newsavebox{\graybox}
\newenvironment{note}
{ \begin{center}\begin{minipage}[c]{\textwidth} \begin{lrbox}{\graybox}
\begin{varwidth}{0.9\textwidth}}
{\end{varwidth}\end{lrbox}
\includegraphics[width=0.077\textwidth]{note3.png} \colorbox{Gray!50}{\usebox{\graybox}}\end{minipage}\end{center}}
\begin{document}
\begin{note}
He was an Austrian physicist famous for his founding contributions in the fields of
statistical mechanics and statistical thermodynamics. He was one of the most
important advocates for atomic theory at a time when that scientific model was
still highly controversial.\\
\end{note}
\end{document}
答案1
对于垂直居中,您需要在图像的垂直中心定义图像的基线。为此,建议使用adjustbox
选项valign=m
:
\documentclass{article}
\usepackage{varwidth}
\usepackage[demo]{graphicx}
\usepackage[export]{adjustbox}
\usepackage{xcolor}
\newsavebox{\graybox}
\newenvironment{note}
{\begin{center}
\begin{minipage}{\textwidth}
\begin{lrbox}{\graybox}
\begin{varwidth}{0.80\textwidth}
}{\end{varwidth}
\end{lrbox}
\includegraphics[width=0.15\textwidth,valign=m]{note3.png}\hfill
\colorbox{gray!30}{\usebox{\graybox}}
\end{minipage}
\end{center}
}
\usepackage{lipsum}
\begin{document}
\lipsum[11]
\begin{note}
He was an Austrian physicist famous for his founding contributions in the fields of
statistical mechanics and statistical thermodynamics. He was one of the most
important advocates for atomic theory at a time when that scientific model was
still highly controversial.
\end{note}
\lipsum[11]
\end{document}