何らかの理由で、数式環境と同じようにインライン図 (つまり、フロートなし) があると便利だと思いました。後で参照できるようにするため、番号を付ける必要があります。私は 2 つの試みを思いつきましたが、どちらにも欠点があります。私を整理できるフィードバックを期待しています。
最初の試行では、3 つのミニページを使用します (以下のコードを参照)。図の番号が図の中央に縦に並んでいるので見栄えがします。しかし、図の幅がページの幅に近づくにつれて、物事は崩壊し始めます。また、改ページではうまく動作しません。
2 回目の試行では、異なるラベルの式環境を使用します。これが賢明なことかどうかわからないという事実は別として、次の段落の先頭に余分な空白が生成されます。また、ラベルを中央に垂直に揃えるのではなく、下に配置します。
両方の試行の例を次に示します。
\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}
欠点を修正するためのより良いアイデアや提案はありますか? ありがとう!