如何将图形和文本对齐到小页面的垂直中心?

如何将图形和文本对齐到小页面的垂直中心?
\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}

在此处输入图片描述

相关内容