左/中/右引用子图

左/中/右引用子图

我有一张图,其中包含三个子图,如下面的代码示例所示。我如何更改对子图的引用,以便我拥有图 1(左)、图 1(中)和图 1(右),而不是图 1.1、1.2 和 1.3?此外,在标题中,我希望它有一个通用标题,然后在同一段落中具有(左)左标题(中)中标题(右)右标题。

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure*}
\begin{minipage}[b]{0.33\linewidth}
\label{fig:left}
\includegraphics[width=2.5in,height=2.5in]{img1}
\end{minipage}
\begin{minipage}[b]{0.33\linewidth}
\includegraphics[width=2.5in,height=2.5in]{img2}
\label{fig:center}
\end{minipage}
\begin{minipage}[b]{0.33\linewidth}
\includegraphics[width=2.5in,height=2.5in]{img3}
\label{fig:right}
\end{minipage}
\caption{
    Blah blah blah.  
    \ref{fig:left} blah blah.   
    \ref{fig:center} blah blah.   
    \ref{fig:right} blah blah.
}
\label{fig:all}
\end{figure*}
\end{document}

答案1

接下来,\lcr定义了一个名为 的新编号系统(其工作方式与 、 等相同\arabic\alph,将“左”与“1”关联,“中心”与“2”关联,“右”与“3”关联。

然后使用该prettyref包自定义对三个“子图”之一的交叉引用。请注意,\phantomsubcaption必须使用 才能为 创建 的锚点\ref

\documentclass{article}

\makeatletter
\def\lcr#1{\expandafter\@lcr\csname c@#1\endcsname}% LaTeX
\def\@lcr#1{%
  \ifnum#1=0%
    \@ctrerr% 
  \else\ifnum#1=1%
      left%
    \else\ifnum#1=2%
       center%
     \else\ifnum#1=3%
        right%
      \else
        \@ctrerr%
      \fi
    \fi
  \fi
}
\makeatother

\usepackage{subcaption}

\DeclareCaptionSubType*{figure}
\renewcommand\thesubfigure{\thefigure~(\lcr{subfigure})}

\usepackage{prettyref}
\newrefformat{subfiglcr}{Figure~\ref{#1}}

\usepackage{tikz}
%\usepackage{graphicx}

\begin{document}

\begin{figure*}
    \begin{minipage}[b]{0.3\linewidth}
        \centering
        \begin{tikzpicture}
            \path[draw=red,fill=red!20] (0,0) rectangle (4,4);
        \end{tikzpicture}
        \phantomsubcaption \label{subfiglcr:left}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.3\linewidth}
        \centering
        \begin{tikzpicture}
            \path[draw=green,fill=green!20] (0,0) rectangle (4,4);
        \end{tikzpicture}
        \phantomsubcaption \label{subfiglcr:center}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.3\linewidth}
        \centering
        \begin{tikzpicture}
            \path[draw=blue,fill=blue!20] (0,0) rectangle (4,4);
        \end{tikzpicture}
        \phantomsubcaption \label{subfiglcr:right}
    \end{minipage}
    \caption{Three squares. Left: red. Center: green. Right: blue.}
    \label{fig:all}
\end{figure*}

\prettyref{subfiglcr:left} shows a typical example of red square;
\prettyref{subfiglcr:center} shows a particularly interesting specimen of green square,
while \prettyref{subfiglcr:right} shows a common and rather unremarkable blue square.

\end{document}

在此处输入图片描述

在这个例子中,tikz使用包代替了graphicx(OP使用的)包,以便生成一些占位符图片。

答案2

如果您希望仅对特定图形进行更改,则可以修改@jub0bs 答案并使用: \renewcommand{\thesubfigure}{\lcr{subfigure}}在图形的开头

\begin{figure}

\renewcommand{\thesubfigure}{\lcr{subfigure}}
\begin{minipage}[b]{.33\linewidth}

    \centering\large A
    \subcaption{A subfigure}\label{fig:1a}
\end{minipage}%
\begin{minipage}[b]{.33\linewidth}
    \centering\large B
    \subcaption{Another subfigure}\label{fig:1b}
\end{minipage}%
\begin{minipage}[b]{.33\linewidth}
    \centering\large C
    \subcaption{Yet another}\label{fig:1c}
 \end{minipage}
   \caption{A figure}\label{fig:1}
 \end{figure}

 Figure~\ref{fig:1a}

完整代码:

\documentclass{article}

\makeatletter
\def\lcr#1{\expandafter\@lcr\csname c@#1\endcsname}% LaTeX
\def\@lcr#1{%
  \ifnum#1=0%
    \@ctrerr% 
  \else\ifnum#1=1%
      left%
    \else\ifnum#1=2%
       center%
     \else\ifnum#1=3%
        right%
      \else
        \@ctrerr%
      \fi
    \fi
  \fi
}
\makeatother

\usepackage{subcaption}

\DeclareCaptionSubType*{figure}
\renewcommand\thesubfigure{\thefigure~(\lcr{subfigure})}

\usepackage{prettyref}
\newrefformat{subfiglcr}{Figure~\ref{#1}}

\usepackage{tikz}
%\usepackage{graphicx}

\begin{document}
\begin{figure}

\renewcommand{\thesubfigure}{\lcr{subfigure}}
\begin{minipage}[b]{.33\linewidth}

    \centering\large A
    \subcaption{A subfigure}\label{fig:1a}
\end{minipage}%
\begin{minipage}[b]{.33\linewidth}
    \centering\large B
    \subcaption{Another subfigure}\label{fig:1b}
\end{minipage}%
\begin{minipage}[b]{.33\linewidth}
    \centering\large C
    \subcaption{Yet another}\label{fig:1c}
 \end{minipage}
   \caption{A figure}\label{fig:1}
 \end{figure}

 Figure~\ref{fig:1a}

\end{document}

相关内容