如何在固定大小的框架中将文本和图形垂直居中?(理想情况下是在 achemso 包中的 tocentry 环境中。)

如何在固定大小的框架中将文本和图形垂直居中?(理想情况下是在 achemso 包中的 tocentry 环境中。)

我正在尝试将包含文本和图片的目录条目添加到 ACS 论文草稿中。我希望所有内容都放在宽度为 3.25 英寸、高度为 1.75 英寸的框中,图片在右侧,文本在左侧,所有内容都垂直居中。我该如何实现?

这是我当前的最小工作示例,说明了该问题:

\documentclass[journal=apchd5,manuscript=letter]{achemso}
\title{Title}

\begin{document}

% required max size
\includegraphics[width=3.25in, height=1.75in]{example-image-a}

% what I think mimics the ACS tocentry environment
\begin{center}
  \fbox{
    \begin{minipage}{3.25in}
      \vbox to 1.75in{
        \parbox[c]{0.5\textwidth}{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Arcu non odio euismod lacinia at quis risus sed vulputate.}\includegraphics[width=0.5\textwidth]{example-image-a}
      }
    \end{minipage}
  }
\end{center}

% ACS tocentry environment
\begin{tocentry}
  \parbox[c]{0.5\textwidth}{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Arcu non odio euismod lacinia at quis risus sed vulputate.}\includegraphics[width=0.5\textwidth]{example-image-a}
\end{tocentry}

\end{document}

我无法让文本和图形垂直居中。此外,框架的高度最终超过了 height=1.75in。

如何将文本和图形垂直居中在固定大小的框架框中?如何在 achemso 包的 tocentry 环境中执行此操作?

答案1

这是另一个版本,alttocentry它将保持框大小正确,除非文本对于空间来说太多。首先,我\rule向右下方显示 以确认尺寸。

可调整的参数包括\fboxsep\fboxrule\mygap\imgwd\boxwd\boxht

\documentclass[journal=apchd5,manuscript=letter]{achemso}
\usepackage{stackengine}
\newlength\mygap
\setlength\mygap{5pt}
\newlength\boxwd
\setlength\boxwd{3.25in}
\newlength\boxht
\setlength\boxht{1.75in}
\newlength\imgwd
\setlength\imgwd{.5\boxwd}
\newcommand\mytextwd{\boxwd-\imgwd-\fboxsep-\fboxrule-\mygap}
\newcommand\mytextenv{\setstretch{1.1}\sffamily}
\newcommand\myboxshift{-.5\dimexpr\height-.5\ht\strutbox+.5\dp\strutbox\relax}
\newcommand\myboxopts{width=\imgwd-\fboxsep-\fboxrule}
\newcommand\myaddgap{.5\boxht-.5\ht0-.5\dp0-\fboxsep-\fboxrule}
\newenvironment{alttocentry}[1]{
  \def\myimgname{#1}%
  \setbox0=\hbox\bgroup\begin{minipage}{\mytextwd}\mytextenv\strut\ignorespaces
}{%
  \end{minipage}%
  \kern\mygap%
  \raisebox{\myboxshift}%
  {\expandafter\includegraphics\expandafter[\myboxopts]{\myimgname}}%
  \egroup%
  \centerline{\fbox{\addstackgap[\myaddgap]{\copy0}}%
  \showboxht%%%%% CAN GET RID OF THIS
  }%
}
%%%%% CAN GET RID OF THESE, ONCE HAPPY WITH RESULT
\newcommand\showboxht{%
  \rlap{\,\rule[-.5\boxht+.35\ht\strutbox-.35\dp\strutbox]{3pt}{\boxht}}}
\newcommand\showboxwd{\par\centerline{\rule{3.25in}{3pt}}}
%%%%%%%%%
\title{Title}
\begin{document}
\begin{alttocentry}{example-image-a}
  Lorem ipsum dolor sit amet, 
  consectetur adipiscing elit, 
  sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.%
\end{alttocentry}
\showboxwd%%%%% CAN GET RID OF THIS
\bigskip

\let\showboxht\relax
\setlength\imgwd{.45\boxwd}

\begin{alttocentry}{example-image-b}
This is a test of an toc entry smaller than the figure.
\textbackslash imgwd reduced.
\end{alttocentry}
\begin{alttocentry}{example-image-b}
This is a test of an toc entry larger than allowed vertical space.
This is a test of an toc entry larger than allowed vertical space.
This is a test of an toc entry larger than allowed vertical space.
This is a test of an toc entry larger than allowed vertical space.
\end{alttocentry}
\end{document}

在此处输入图片描述

我不确定实际tocentry环境是否保留了垂直维度。但这是我使用实际环境的尝试。

\documentclass[journal=apchd5,manuscript=letter]{achemso}
\title{Title}
\begin{document}
% ACS tocentry environment
\begin{tocentry}
\vfill
  \begin{minipage}{0.5\textwidth}Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
  sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \end{minipage}%
  \raisebox{-.5\dimexpr\height-\ht\strutbox+\dp\strutbox\relax}%
  {\includegraphics[width=0.5\textwidth]{example-image-a}}
\\\vfill
\end{tocentry}
\end{document}

在此处输入图片描述

相关内容