0

I'm wondering what is the cleanest and simplest way to add a subfloat label (like (a)) at the bottom left of a tikzpicture or pgfplot. I generally export plots from matlab with matlab2tikz with this command matlab2tikz('Figure_name.tikz', 'height', '\figureheight', 'width', '\figurewidth');, but I don't mind manually editing the resulting file, as I anyhow need to make some cosmetic changes.

There are already some posts like Reference pgfplots' groupplot with subcaption or Placing a label in specific corner of the chart, but the location differs from what I would like to achieve.

Similarly, in Put subfigure labels inside figures using subfig package, there is a small macro defined to place the label exactly where I want if the code is modified into the following:

\newcommand{\subfigimg}[3][,]{%
  \setbox1=\hbox{\includegraphics[#1]{#3}}% Store image in box
  \leavevmode\rlap{\usebox1}% Print image
  \rlap{\hspace*{5pt}\raisebox{.5\baselineskip}{\sffamily\footnotesize{#2}}}% Print label
  \phantom{\usebox1}% Insert appropriate spacing
}

When using a tikzpicture I modified the previous macro into

\newcommand{\modsubfigimg}[2][,]{%
  \setbox1=\hbox{#1}% Store image in box
  \leavevmode\rlap{\usebox1}% Print image
  \rlap{\hspace*{5pt}\raisebox{.5\baselineskip}{\small{#2}}}% Print label
  \phantom{\usebox1}% Insert appropriate spacing
}

but the result is not satisfactory visually.

Right now I'm using the following code snippet (with \tikzexternalize, but that's not relevant here), and the alignment inside each minipage is messed up (\centering can't be used for instance).

\begin{minipage}[b]{.5\textwidth}
\tikzsetnextfilename{PD-PWM_carrier_band}%
    \modsubfigimg[(a)]{\input{gfx/PDPWM_carrier_band.tikz}}
\end{minipage}%
\begin{minipage}[b]{.5\textwidth}
\tikzsetnextfilename{PS-PWM_carrier_band}%
    \modsubfigimg[(b)]{\input{gfx/PSPWM_carrier_band.tikz}}
\end{minipage}
2

Something like this?

\documentclass{standalone}
\usepackage{pgfplots}

\newcounter{subfig}[figure]
\renewcommand{\thesubfig}{\alph{subfig}}

\begin{document}

\begin{tikzpicture}
\begin{axis}
\addplot coordinates {(0,0) (1,10)}; 
\end{axis}
\node[below left] at (current bounding box.south west) {\stepcounter{subfig}(\thesubfig)};
\end{tikzpicture}

\end{document}

demo

  • It does well the job, if I modify below left to above right and move the \stepcounter{subfig} when using \tikzexternalize. – s__C Oct 26 '16 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.