将标题置于 TIKZ 下方中央

将标题置于 TIKZ 下方中央

我想要以下两张带标题的图表以下图表,每个标题都恰好位于图表下方的中间。我已运行以下操作,但标题最终出现在不同位置。有什么提示吗?

我放置了相当长的占位符标题,因为我的标题需要超过 1-2 行。

  \usepackage{pgfplots}
    \begin{document}
    \begin{figure}[h]
    \centering
    \begin{minipage}[b][5cm][s]{.45\textwidth}
    \centering
    \vfill
    \begin{tikzpicture}[scale=2.913]
    \clip (-1,-0.5) rectangle (1.785,1.785);
    {
    \draw[red] plot[domain=0:4, range=0:4, variable=\x,samples=90]  ({\x},{max(0.7*(3*log10(\x+0.23)+4*(abs(\x-0.35))^0.1-2.6+0.67*(abs(\x-0.35))^1.63/12),0)});
    \draw[blue] plot[domain=0:4, range=0:4, variable=\x,samples=90]  ({\x},{1.24*(\x^2.576)/(0.2+\x^2.24)});
    \draw[green] plot[domain=0:4, range=0:4, variable=\x,samples=90]  ({\x},{1.24*(\x^(1.15*1.4))/(0.21+\x^1.4)});
    \draw[black] plot[domain=0:4, range=0:4, variable=\x,samples=90]  ({\x},{1.24*(\x^(1.22*0.5))/(0.21+\x^0.5)});
    }
    \draw (0,0) rectangle (1.785,1.785);
    \draw [dotted] (1,0) node[below]{$1$} -- (1,3);
    \draw [dotted] (0,1.1161) node[left]{$1$} -- (3,1.1161);
    \node at (1.6065,-0.08925) {$v_1$};
    \node at (-.4,3.85) {\footnotesize $\frac{x_{p}}{x_{s}}$};
    \end{tikzpicture}
    \captionsetup{font=footnotesize}
    \captionof{figure}{caption 1 caption 1caption 1caption 1caption 1caption 1caption 1caption 1caption 1caption 1caption 1
    }
    \vfill
    \vspace{\baselineskip}
    \end{minipage}\qquad
    \begin{minipage}[b][5cm][s]{.45\textwidth}
    \centering
    \vfill
    \begin{tikzpicture}[scale=1.3]
     \clip (-0.7,-0.5) rectangle (4,4);
    {
    \draw[red] plot[domain=0.398:4, range=0:4, variable=\x,samples=90]  ({\x},{max(2.5*(1.35*(abs(\x-0.4))^0.2-(abs(\x-0.4))^1.6/2-0.0115),0)});
    \draw[blue] plot[domain=0:4, range=0:4, variable=\x,samples=90]  ({\x},{2.5*(7*(\x^0.57)/(\x^3+6)-\x/60+\x^2/600+0.0079)});
    \draw[green] plot[domain=0:4, range=0:4, variable=\x,samples=90]  ({\x},{2.5*(7*(\x^0.1)/(\x^(-0.1)+5.5)-\x^1.6/10+\x^2.47/100+0.012)});
    \draw[black] plot[domain=0:4, range=0:4, variable=\x,samples=90]  ({\x},{2.5*(7*(\x^0.1)/(\x^(-0.1)+5.5)-\x^1.6/9+\x^2.15/39+0.008)});
    }
    \draw (0,0) rectangle (4,4);
    \draw [red] (0.39,0) -- (0.398,0.995);
    \draw [dotted] (1,0) node[below]{$1$} -- (1,4);
    \draw [dotted] (0,2.5) node[left]{$1$} -- (4,2.5);
    \node at (3.6,-.2) {$v_1$};
    \node at (-.4,3.85) {q};
    \end{tikzpicture}
    \captionsetup{font=footnotesize}
    \captionof{figure}{caption 2 caption 2caption 2caption 2caption 2caption 2caption 2caption 2caption 2caption 2caption 2caption 2caption 2caption 2
    }
    \vfill
    \end{minipage}
    \end{figure}
    \vspace{3cm}
    \end{document}

答案1

首先,我会将图放在local bounding boxes 中,然后使用它calc来测量它们的宽度,以便在它们下面放置适当宽度的标题。当然,您仍然可以调整一些东西,例如,从局部边界框中排除 y 轴的标签。使用这种方法,您可以完全控制。如果您使用 pgfplots(您已加载但未使用),您甚至可以更好地控制。

\documentclass{article}
\usepackage{caption}
\captionsetup{font=footnotesize}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\begin{document}
    \begin{figure}[h]
    \centering
    \begin{tikzpicture}
    \begin{scope}[local bounding box=pic A,scale=2.913]
    \draw[red] plot[domain=0:1.785, range=0:4, variable=\x,samples=90]  ({\x},{max(0.7*(3*log10(\x+0.23)+4*(abs(\x-0.35))^0.1-2.6+0.67*(abs(\x-0.35))^1.63/12),0)});
    \draw[blue] plot[domain=0:1.785, range=0:4, variable=\x,samples=90]  ({\x},{1.24*(\x^2.576)/(0.2+\x^2.24)});
    \draw[green] plot[domain=0:1.785, range=0:4, variable=\x,samples=90]  ({\x},{1.24*(\x^(1.15*1.4))/(0.21+\x^1.4)});
    \draw[black] plot[domain=0:1.785, range=0:4, variable=\x,samples=90]  ({\x},{1.24*(\x^(1.22*0.5))/(0.21+\x^0.5)});
    \draw (0,0) rectangle (1.785,1.785);
    \draw [dotted] (1,0) node[below]{$1$} -- (1,1.785);
    \draw [dotted] (0,1.1161) node[left]{$1$} -- (1.785,1.1161);
    \node at (1.6065,-0.08925) {$v_1$};
    %\node at (-.4,3.85) {\footnotesize $\frac{x_{p}}{x_{s}}$};
    \end{scope}
    \draw let \p1=($(pic A.south east)-(pic A.south west)$) in 
    node[below=3pt of pic A.south,text width=0.9*\x1,align=center]
    {\captionof{figure}{caption 1 caption 1caption 1caption 1caption 1caption 1caption 1caption 1caption 1caption 1caption 1}};
    \begin{scope}[xshift=8cm,scale=1.3,local bounding box=pic B]
    \draw[red] plot[domain=0.398:4, range=0:4, variable=\x,samples=90]  ({\x},{max(2.5*(1.35*(abs(\x-0.4))^0.2-(abs(\x-0.4))^1.6/2-0.0115),0)});
    \draw[blue] plot[domain=0:4, range=0:4, variable=\x,samples=90]  ({\x},{2.5*(7*(\x^0.57)/(\x^3+6)-\x/60+\x^2/600+0.0079)});
    \draw[green] plot[domain=0:4, range=0:4, variable=\x,samples=90]  ({\x},{2.5*(7*(\x^0.1)/(\x^(-0.1)+5.5)-\x^1.6/10+\x^2.47/100+0.012)});
    \draw[black] plot[domain=0:4, range=0:4, variable=\x,samples=90]  ({\x},{2.5*(7*(\x^0.1)/(\x^(-0.1)+5.5)-\x^1.6/9+\x^2.15/39+0.008)});
    \draw (0,0) rectangle (4,4);
    \draw [red] (0.39,0) -- (0.398,0.995);
    \draw [dotted] (1,0) node[below]{$1$} -- (1,4);
    \draw [dotted] (0,2.5) node[left]{$1$} -- (4,2.5);
    \node at (3.6,-.2) {$v_1$};
    \node at (-.4,3.85) {q};
    \end{scope}
    \draw let \p1=($(pic B.south east)-(pic B.south west)$) in 
    node[below=3pt of pic B.south,text width=0.9*\x1,align=center]
    {\captionof{figure}{caption 2 caption 2caption 2caption 2caption 2caption
    2caption 2caption 2caption 2caption 2caption 2caption 2caption 2caption
    2}};
    \end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

一个可能更清晰的解决方案是基于groupplotpgfplots 的 s,您可以在其中(滥用)使用标题来放置标题。

\documentclass{article}
\usepackage{caption}
\usepackage[margin=1in]{geometry}
\captionsetup{font=footnotesize}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16,every axis title/.append style={at={(0.5,-0.05)},
anchor=north,text width=0.42*\textwidth}}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{calc,positioning}
\begin{document}
\begin{figure}[h]
\centering
 \begin{tikzpicture}
  \begin{groupplot}[group style={group size=2 by 1, horizontal
  sep=0.1*\textwidth},
  xlabel style = {at={(1,0)},anchor=north east},
  xlabel={$v_1$},
  ylabel style = {at={(0,1)},anchor=north east,rotate=-90},
  width=0.45*\textwidth, xtick={1},ytick=\empty]
   \nextgroupplot[domain=0:1.785,
   ymin=0,ymax=2,samples=90,ylabel={$\displaystyle\frac{x_{p}}{x_{s}}$},
    extra y ticks={1.1161},extra y tick labels={1},
    title={\captionof{figure}{This is a very long caption that runs over several
    lines.}}]
    \addplot[red] {max(0.7*(3*log10(\x+0.23)+4*(abs(\x-0.35))^0.1-2.6+0.67*(abs(\x-0.35))^1.63/12),0)};
    \addplot[blue] {1.24*(\x^2.576)/(0.2+\x^2.24)};
    \addplot[green] {1.24*(\x^(1.15*1.4))/(0.21+\x^1.4)};
    \addplot[black] {1.24*(\x^(1.22*0.5))/(0.21+\x^0.5)};
    \draw [dotted] (1,0)  -- (1,4) (-1,1.1161) -- (2,1.1161);
   \nextgroupplot[domain=0.398:4,ymin=0,ymax=4,samples=90,
   extra y ticks={2.5},extra y tick labels={1},ylabel={$q$},
   title={\captionof{figure}{This is another very long caption that runs over several
    lines.}}]
    \addplot[red] {max(2.5*(1.35*(abs(\x-0.4))^0.2-(abs(\x-0.4))^1.6/2-0.0115),0)};
    \addplot[blue] {2.5*(7*(\x^0.57)/(\x^3+6)-\x/60+\x^2/600+0.0079)};
    \addplot[green] {2.5*(7*(\x^0.1)/(\x^(-0.1)+5.5)-\x^1.6/10+\x^2.47/100+0.012)};
    \addplot[black] {2.5*(7*(\x^0.1)/(\x^(-0.1)+5.5)-\x^1.6/9+\x^2.15/39+0.008)};
    \draw [dotted] (1,0)  -- (1,4) (0,2.5) -- (5,2.5);
  \end{groupplot}
 \end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

答案2

  • 你说的“在图表下方居中”是什么意思不是很清楚:-(
  • 因为你没有提供最小的工作示例,所以我从 nice 中摘取了它的序言土拨鼠的回答
  • 使用:

    • minipage
    • pgfplots(您在那两个图中加载但未使用)

    您的图表的 mwe 是:

    \documentclass{article}
    \usepackage[skip=1ex,
                font=footnotesize,
                labelfont=bf] {caption}
    \captionsetup{}
    \usepackage{pgfplots}
    \pgfplotsset{compat=1.16}
    
    %---------------- show page layout. don't use in a real document!
    \usepackage{showframe}
    \renewcommand\ShowFrameLinethickness{0.15pt}
    \renewcommand*\ShowFrameColor{\color{red}}
    %---------------------------------------------------------------%
    
    \begin{document}
        \begin{figure}[h]
        \pgfplotsset{width=1.1\linewidth,
                     xlabel={$v_1$},
                     xlabel style = {at={(1,0)},anchor=north east},
                     ylabel style = {at={(0,1)},anchor=north east,rotate=-90},
                     xtick=\empty,
                     ytick=\empty,
                     extra x ticks={1},
                     extra y ticks={1},
                     grid=major,
                     major grid style={densely dotted},
               enlargelimits=false,
                     samples=90,
                     no marks
                     }
    
        \begin{minipage}[t]{0.48\linewidth}\centering%\raggedleft
            \begin{tikzpicture}[trim axis left]
        \begin{axis}[
                domain=0:2,
                ylabel={$p$}
                    ]
    \addplot {max(0.7*(3*log10(\x+0.23)+4*(abs(\x-0.35))^0.1-2.6+0.67*(abs(\x-0.35))^1.63/12),0)};
    \addplot {1.24*(\x^2.576)/(0.2+\x^2.24)};
    \addplot {1.24*(\x^(1.15*1.4))/(0.21+\x^1.4)};
    \addplot {1.24*(\x^(1.22*0.5))/(0.21+\x^0.5)};
        \end{axis}
        \end{tikzpicture}
    
    \caption{caption 1 caption 1 caption 1 caption 1 caption 1 caption 1caption 1 caption 1 caption 1 caption 1 caption 1}
        \label{fig:fig-1}
        \end{minipage}
    \hfill
        \begin{minipage}[t]{0.48\linewidth}\centering%\raggedleft
            \begin{tikzpicture}[trim axis left]
        \begin{axis}[
                domain=0:4,
                ylabel={$q$},
                ymax=3.3
    %            scaled ticks=false
                    ]
    \addplot +[domain=0.39:4] {max(2.5*(1.35*(abs(\x-0.4))^0.2-(abs(\x-0.4))^1.6/2-0.0115),0)};
    \addplot {2.5*(7*(\x^0.57)/(\x^3+6)-\x/60+\x^2/600+0.0079)};
    \addplot {2.5*(7*(\x^0.1)/(\x^(-0.1)+5.5)-\x^1.6/10+\x^2.47/100+0.012)};
    \addplot {2.5*(7*(\x^0.1)/(\x^(-0.1)+5.5)-\x^1.6/9+\x^2.15/39+0.008)};
        \end{axis}
        \end{tikzpicture}
    
    \caption{caption 2 caption 2 caption 2 caption 2 caption 2 caption 2 caption 2 caption 2 caption 2 caption 2 caption 2 caption 2 caption 2 caption 2}
        \label{fig:fig-1}
        \end{minipage}
    \end{figure}
    

    \结束{文档}

在此处输入图片描述

(红线表示文字边框)

相关内容