Utilice un cuadro delimitador y una figura medida para alinear el título.

Utilice un cuadro delimitador y una figura medida para alinear el título.

Utilizo useasboundingboxen mis imágenes tikz para centrarlas ópticamente. Quiero que el título esté alineado con el borde izquierdo del cuadro delimitador. Normalmente esto se puede hacer con el measuredfigureentorno de threeparttable. En el código siguiente no es así. ¿Qué estoy haciendo mal? El título debe estar alineado con el eje y, que es el borde izquierdo del cuadro delimitador.

(Perdón por el ejemplo mínimo no tan mínimo. Establecí parámetros para varios gráficos a nivel mundial y no sé dónde radica el problema).

\documentclass{article}

\usepackage{tikz}
\usepackage{threeparttable}
\usepackage{calc}
\usepackage[singlelinecheck=false]{caption}


\begin{document}
\newlength\plotheight % Height of plotting area
\setlength\plotheight{.4\textwidth}
\newlength\plotwidth % Width of plotting area
\setlength\plotwidth{.7\textwidth}
\newlength\axissep % Space between plotting area and axis
\setlength\axissep{\parindent}
\newlength\tickl % Length of minor ticks
\setlength\tickl{2mm}
\newlength\ylabsep % space between plotting area and ylab 
\setlength\ylabsep{\axissep+\tickl+2em}
\newlength\xlabsep % space between plotting area and ylab 
\setlength\xlabsep{\axissep+\tickl+2em}



\begin{figure}
\begin{measuredfigure}
\caption{Some caption}

\def\maxy{50}
\def\miny{0}
\def\maxx{40}
\def\minx{0}
\def\xlab{x-label}
\def\ylab{y-label}

\begin{tikzpicture}[y=\plotheight/(\maxy-\miny)
        , x=\plotwidth/(\maxx-\minx)]

\useasboundingbox (\miny-\axissep,\miny-\xlabsep)  
    rectangle (\maxx,\maxy);

% y-axis
\draw (\minx-\axissep,\miny) -- (\minx-\axissep,\maxy);
% y-ticks
\foreach \x/\l in {\miny,10,...,\maxy} 
    {\draw (\minx,\x) ++ (-\axissep,0) -- ++ (-\tickl,0)
% y-ticklabels    
        node[anchor=east] {\l};}
% y-label
    \path  (\minx-\ylabsep, {(\miny+\maxy)/2}) node[rotate=90 ,anchor=south] {\ylab};

% x-axis
\draw (\minx,\miny) ++ (0,-\axissep) -- ++ (\maxx,0);

% x-ticks
\foreach \x in {0,10,...,\maxx} 
    \draw (\x, \miny) ++ (0,-\axissep) -- ++ (0, -\tickl)
% x-ticklabels
        node [anchor=north] {\x};
% x-label
    \path ({(\minx+\maxx)/2},\miny) ++ (0, -\xlabsep)
    node[anchor=north] {\xlab};


\end{tikzpicture}

\end{measuredfigure}
\end{figure}

\end{document}

ingrese la descripción de la imagen aquí

Respuesta1

Tienes varios espacios espurios. Agregue %al final de las líneas dentro del measuredfigureentorno.

\documentclass{article}
\usepackage{tikz}
\usepackage{threeparttable}
\usepackage{calc}
\usepackage[singlelinecheck=false]{caption}

\begin{document}

\newlength\plotheight % Height of plotting area
\setlength\plotheight{.4\textwidth}
\newlength\plotwidth % Width of plotting area
\setlength\plotwidth{.7\textwidth}
\newlength\axissep % Space between plotting area and axis
\setlength\axissep{\parindent}
\newlength\tickl % Length of minor ticks
\setlength\tickl{2mm}
\newlength\ylabsep % space between plotting area and ylab 
\setlength\ylabsep{\axissep+\tickl+2em}
\newlength\xlabsep % space between plotting area and ylab 
\setlength\xlabsep{\axissep+\tickl+2em}

\begin{figure}
  \centering% <- added code
  \begin{measuredfigure}
    \caption{Some caption}%
    %
    \def\maxy{50}%
    \def\miny{0}%
    \def\maxx{40}%
    \def\minx{0}%
    \def\xlab{x-label}%
    \def\ylab{y-label}%
    %
    \begin{tikzpicture}[y=\plotheight/(\maxy-\miny)
            , x=\plotwidth/(\maxx-\minx)]
      % bounding box
      \useasboundingbox(\minx-\axissep,\miny-\xlabsep)  
        rectangle (\maxx,\maxy);
      % y-axis
      \draw (\minx-\axissep,\miny) -- (\minx-\axissep,\maxy);
      % y-ticks
      \foreach \x/\l in {\miny,10,...,\maxy} 
          {\draw (\minx,\x) ++ (-\axissep,0) -- ++ (-\tickl,0)
      % y-ticklabels    
              node[anchor=east] {\l};}
      % y-label
          \path  (\minx-\ylabsep, {(\miny+\maxy)/2}) node[rotate=90 ,anchor=south] {\ylab};
      % x-axis
      \draw (\minx,\miny) ++ (0,-\axissep) -- ++ (\maxx,0);
      % x-ticks
      \foreach \x in {0,10,...,\maxx} 
          \draw (\x, \miny) ++ (0,-\axissep) -- ++ (0, -\tickl)
      % x-ticklabels
              node [anchor=north] {\x};
      % x-label
          \path ({(\minx+\maxx)/2},\miny) ++ (0, -\xlabsep)
          node[anchor=north] {\xlab};
      % drawing the bounding box
      \draw[red](current bounding box.south west)
        rectangle(current bounding box.north east);
    \end{tikzpicture}%
  \end{measuredfigure}
\end{figure}
\end{document}

Tenga en cuenta que lo he utilizado \centeringdentro del figureentorno para centrar la imagen. El cuadro delimitador se muestra mediante el rectángulo rojo.

ingrese la descripción de la imagen aquí

información relacionada