asboudingbox 및 측정값을 사용하여 캡션 정렬

asboudingbox 및 측정값을 사용하여 캡션 정렬

나는 useasboundingboxtikz 사진을 광학적으로 중앙에 맞추는 데 사용합니다. 캡션을 경계 상자의 왼쪽 가장자리에 정렬하고 싶습니다. 일반적으로 이는 의 measuredfigure환경 에서 수행될 수 있습니다 threeparttable. 아래 코드에서는 그렇지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 캡션은 경계 상자의 왼쪽 가장자리인 y축에 맞춰 정렬되어야 합니다.

(최소한의 예가 아니어서 죄송합니다. 전 세계적으로 여러 플롯에 대한 매개변수를 설정했는데 문제가 어디에 있는지 모르겠습니다.)

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

여기에 이미지 설명을 입력하세요

답변1

여러 개의 가짜 공간이 있습니다. 환경 %내부의 줄 끝에 추가하십시오 measuredfigure.

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

그림을 중앙에 배치하기 위해 환경 \centering내부를 사용했습니다 . figure경계 상자는 빨간색 직사각형으로 표시됩니다.

여기에 이미지 설명을 입력하세요

관련 정보