1
\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}

How to center both the graph and text at the vertical center of a minpage? Now the graph is higher than the text. enter image description here

3
  • welcome to tex.se! please extend your code sniped to complete small document beginning with \documentclass{...} and ending with \end{document}.
    – Zarko
    Commented Sep 14, 2017 at 7:08
  • I have extended my code @Zarko
    – K.Robert
    Commented Sep 14, 2017 at 7:18
  • only with end{document} :-) and with \documentclass{...} on wrong place. still missing some package ... see my answer below.
    – Zarko
    Commented Sep 14, 2017 at 7:31

1 Answer 1

2

for vertical centering you need to define baseline of your image on its vertical center. for this is sugest to use adjustbox and option valign=m option:

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .