2010-03-05 85 views
2

由于某些原因,我认为如果使用方程式环境,可以使用内联数字(即无浮点数)。他们将不得不被编号,因为我希望能够在以后提及他们。我想出了两次尝试,但都有缺点。我希望得到一些可以帮我解决问题的反馈。在LaTeX中使用方程式编号的内联数字

第一次尝试使用3个小型脚本(请参阅下面的代码)。这看起来不错,因为图号与图的中间垂直对齐。但是,随着图形的宽度接近页面宽度,事情开始崩溃。另外,它在分页时不会表现的非常好。

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

这里的两个尝试的例子:

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

难道你们有什么更好的意见或建议,以解决任何缺点?谢谢!

+1

我以什么方式解决第一个解决方案? – Timo 2010-03-05 11:47:02

回答

3

如果您使用"float"包,则可以指定H作为展示位置,这使得它看起来完全“在这里”。

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