我正在编写一份包含分步说明的实验室手册。一些说明包括屏幕截图。为了使屏幕截图与方向一致,我使用了 samepage。我正在探索一种可以提高效率的环境。问题是我希望屏幕截图居中,但不希望文本行居中。是否可以编写这样的环境?这是我的 MWE。
\documentclass[twoside,openright,12pt]{report}
\def\usletterpaper{\usepackage[bottom=1in,hmarginratio=1:1,letterpaper]{geometry}}
\usepackage{graphicx}
\newenvironment{myItem}{%
\item
\begin{samepage}
\begin{center}
}
{
\end{center}
\end{samepage}
}
\begin{document}
\chapter{Chapter Blah} \label{chap:ChpBlah}
Chapter text here.
\begin{enumerate}
\item Step directions here.
\item Step directions here too.
\begin{myItem}Open Chrome or Firefox and browse to url here.
\includegraphics[scale=0.55]{AnyImage.png}\end{myItem} %only the image should be centered
\end{enumerate}
\end{document}
答案1
由于环境myItem
实际上是从center
环境开始的,因此在\begin{myItem}
故意之后写的任何内容都会被居中(除非另外移动)。
我建议对描述文本使用一个(可选)参数,这样将首先提供描述文本\item #1
,然后进行居中。
\documentclass[twoside,openright,12pt]{report}
\def\usletterpaper{\usepackage[bottom=1in,hmarginratio=1:1,letterpaper]{geometry}}
\usepackage{graphicx}
\newenvironment{myItem}[1][]{%
\item #1
\begin{samepage}
\begin{center}
}
{%
\end{center}
\end{samepage}
}
\begin{document}
\chapter{Chapter Blah} \label{chap:ChpBlah}
Chapter text here.
\begin{enumerate}
\item Step directions here.
\item Step directions here too.
\begin{myItem}[Open Chrome or Firefox and browse to url here.]
\includegraphics[scale=0.2]{ente}\end{myItem} %only the image should be centered
\end{enumerate}
\end{document}
检查是否#1
使用:
\documentclass[twoside,openright,12pt]{report}
\def\usletterpaper{\usepackage[bottom=1in,hmarginratio=1:1,letterpaper]{geometry}}
\usepackage{graphicx}
\usepackage{etoolbox}
\newenvironment{myItem}[1][]{%
\notblank{#1}{
\item #1
}{}
\begin{samepage}
\begin{center}
}
{%
\end{center}
\end{samepage}
}
\begin{document}
\chapter{Chapter Blah} \label{chap:ChpBlah}
Chapter text here.
\begin{enumerate}
\item Step directions here.
\item Step directions here too.
\begin{myItem}[Open Chrome or Firefox and browse to url here.]
\includegraphics[scale=0.2]{ente}\end{myItem} %only the image should be centered
\end{enumerate}
\clearpage
\begin{enumerate}
\item Step directions here.
\item Step directions here too.
\begin{myItem}
\includegraphics[scale=0.2]{ente}
\end{myItem}
\end{enumerate}
\end{document}
答案2
以下myItem
环境重新定义\includegraphics
为将图像置于中心。因此,您可以将内容前或者后图像,并且它们将按照先前的设置进行调整。
\documentclass[twoside,openright,12pt]{report}
\usepackage{graphicx}
\newenvironment{myItem}{%
\item%
\let\oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[2][]{%
\par\nobreak
{\centering\oldincludegraphics[##1]{##2}\par}}
}{}
\begin{document}
\chapter{Chapter Blah}
Chapter text here.
\begin{enumerate}
\item Step directions here.
\item Step directions here too.
\begin{myItem}
Open Chrome or Firefox and browse to URL here.
\includegraphics[scale=0.55]{example-image}%only the image should be centered
\end{myItem}
\end{enumerate}
\end{document}
我稍微简化了示例,因为看起来您似乎不想在图片后面添加文字。但是,如果您确实想添加文字,也可以找到解决方法,让内容保留在同一页面上。