2

出于某种原因,我认为像方程式环境一样拥有内联数字(即没有浮点数)会很好。它们必须被编号,因为我希望以后能够引用它们。我提出了两次尝试,但都有各自的缺点。我希望有一些反馈可以解决我的问题。

第一次尝试使用 3 个 minipages(参见下面的代码)。这看起来不错,因为图形编号与图形中间垂直对齐。然而,当图形的宽度接近页面的宽度时,事情就开始崩溃了。此外,它在分页符处的表现也不是很好。

第二次尝试使用带有不同标签的 equation 环境。除了我不知道这样做是否明智之外,它还会在下一段的开头产生额外的空白。它也不会在中心垂直对齐标签,而是将其放在底部。

这是两种尝试的示例:

\documentclass{article}
\usepackage{pgf,tikz}
\usepackage{lipsum}

%
% Attempt 1
%
% Uses 3 minipages.
% Breaks if figure is wide, and at the bottom of a page.
%

\usepackage{calc}
\newlength{\figlabelwidth} % width of label
\newlength{\imgwidth} % max. width of figure

\newenvironment{inlinefig1}
{
 \refstepcounter{figure} % increase figure number
 \begin{center} % don't know if this is necessary
 \setlength{\figlabelwidth}{\widthof{(Fig. \thefigure)}} 
 \setlength{\imgwidth}{\textwidth - \figlabelwidth - \figlabelwidth} 
 \setlength{\imgwidth}{0.9\imgwidth} % to be on the safe side
 \begin{minipage}{\figlabelwidth}\makebox[\figlabelwidth]{}\end{minipage} % ghost minipage for centering
 \hfill
 \begin{minipage}{\imgwidth}\begin{center} % minipage for figure
}
{
 \end{center}\end{minipage}
 \hfill
 \begin{minipage}{\figlabelwidth}(Fig. \thefigure)\end{minipage} % minipage for label
 \end{center}
}

%
% Attempt 2
%
% Uses an equation environment with relabeled labels.
% Label is not centered vertically, and produces extra whitespace in the paragraph after it.
%

\def\theoldequation{\theequation} % save the old equation format

\newenvironment{inlinefig2}
{
 \refstepcounter{figure} % increase figure number
 \def\theequation{Fig. \arabic{figure}} % switch to figure numbering
 \begin{equation}
}
{
 \end{equation}
 \def\theequation{\theoldequation} % reset to old equation label format
 \addtocounter{equation}{-1} % correct the equation numbering
}

\begin{document}
\noindent \lipsum[1]
\begin{inlinefig1}
 \begin{tikzpicture}
  \draw (0,0) grid +(12,2);
 \end{tikzpicture}
\end{inlinefig1}
\lipsum[2]
\begin{inlinefig2}
 \begin{tikzpicture}
  \draw (0,0) grid +(12,2);
 \end{tikzpicture}
\end{inlinefig2}
\lipsum[3]
\end{document}

你们有什么更好的想法或建议来解决任何缺点吗?谢谢!

4

2 回答 2

3

如果您使用“浮动”包,您可以指定H为展示位置,这使得它完全显示在“此处”。

于 2010-03-05T11:56:32.730 回答
0
\newbox\inlinefigbox
\newenvironment{inlinefig3} 
{
\refstepcounter{figure} % increase figure number 
\setbox\inlinefigbox=\hbox\bgroup
}
{
\egroup
\hbox to \hsize{\hfil \box \inlinefigbox \hss (Fig. \arabic{figure})}
}
于 2010-03-05T12:59:05.003 回答