小页面图片格式奇怪

小页面图片格式奇怪

我有这两张图片并排放置,但不知为何它们的对齐方式很奇怪。我想将左侧的图片与左边距对齐,将右侧的图片与右边距对齐...我该如何解决这个问题?

外观

\begin{figure}[h]
\begin{minipage}[b]{0.5\textwidth}
  \centering
 \begin{tikzpicture}
 \centering
\begin{axis}[
    height = 3 cm,
    width = 7 cm,
    axis lines = left,
    xtick pos=left,
    hide y axis,
    xlabel={$X$},
    xmin=0, xmax=105,
    ymin=-3, ymax=3,
    enlarge y limits = false,
    xtick={0,20,40,60,80,100},
    xticklabels={$X_{0}$, $X_{1}$, , , $X_{L-1}$, $X_{L}$}
]
\addplot[
    only marks,
    color=black,
    mark=*,
    ]
    coordinates {
    (0, 0)(20, 0)(40, 0)(60, 0)(80, 0)(100, 0) 
    };
\addplot +[mark=none, color=gray] coordinates {(20, 0) (40, 0)};
\addplot +[mark=none, color=black] coordinates {(0, -1) (0, 1)(100, 1) (100, -1) (0, -1)};
\node[] at (axis cs: 30,2) {$\Delta X$};
\end{axis}
\end{tikzpicture}
    \caption{Mesh for a 1D problem}
    \label{fig:fdm_1d_mesh}
\end{minipage}
\hfill
\begin{minipage}[b]{0.5\textwidth}
  \centering
 \begin{tikzpicture}
 \centering
\begin{axis}[
    axis lines = left,
    xtick pos=left,
    ytick pos=left,
    xlabel={$X$},
    ylabel={$Y$},
    xmin=0, xmax=105,
    ymin=0, ymax=130,
    xtick={0,20,40,60,80,100},
    xticklabels={$X_{0}$, $X_{1}$, , , $X_{L-1}$, $X_{L}$},
    ytick={0,20,40,60,80,100,120},
    yticklabels={$Y_{0}$, $Y_{1}$, , , , $Y_{M-1}$, $Y_{M}$},
    ymajorgrids=true,
    xmajorgrids=true,
    grid style=dashed,
]
\addplot[
    only marks,
    color=black,
    mark=*,
    ]
    coordinates {
    (0, 0)(0, 20)(0,40)(0,60)(0,80)(0,100)(0,120)
    
    (20, 0)(20, 20)(20,40)(20,60)(20,80)(20,100)(20,120)
    
    (40, 0)(40, 20)(40,40)(40,60)(40,80)(40,100)(40,120)
    
    (60, 0)(60, 20)(60,40)(60,60)(60,80)(60,100)(60,120)
    
    (80, 0)(80, 20)(80,40)(80,60)(80,80)(80,100)(80,120)
    
    (100, 0)(100, 20)(100,40)(100,60)(100,80)(100,100)(100,120)
    
    };
\addplot +[mark=none, color=gray] coordinates {(20, 60) (20, 80)};
\node[] at (axis cs: 14,70) {$\Delta Y$};
\addplot +[mark=none, color=gray] coordinates {(20, 60) (40, 60)};
\node[] at (axis cs: 30,54) {$\Delta X$};
\end{axis}
\end{tikzpicture}
    \caption{Mesh for a 2D problem}
    \label{fig:fdm_2d_mesh}
\end{minipage}
\end{figure}

答案1

右边tikzpicture太宽,放不进去0.5\textwidth,溢出到了边距。

对代码的最小更改是使用 进行缩放(两个图形,保持相同的字体大小和距离)\begin{tikzpicture}[scale=0.8]

标有% <<<<<< changed

F

\documentclass[12pt,a4paper]{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.17}

\usepackage{showframe} % show margins

\begin{document}
    
\begin{figure}[h]
    \begin{minipage}[b]{0.5\textwidth}
        \centering
        \begin{tikzpicture}
        \centering
        \begin{axis}[
        height = 3 cm,
        width = 7 cm,
        axis lines = left,
        xtick pos=left,
        hide y axis,
        xlabel={$X$},
        xmin=0, xmax=105,
        ymin=-3, ymax=3,
        enlarge y limits = false,
        xtick={0,20,40,60,80,100},
        xticklabels={$X_{0}$, $X_{1}$, , , $X_{L-1}$, $X_{L}$}
        ]
        \addplot[
        only marks,
        color=black,
        mark=*,
        ]
        coordinates {
            (0, 0)(20, 0)(40, 0)(60, 0)(80, 0)(100, 0) 
        };
        \addplot +[mark=none, color=gray] coordinates {(20, 0) (40, 0)};
        \addplot +[mark=none, color=black] coordinates {(0, -1) (0, 1)(100, 1) (100, -1) (0, -1)};
        \node[] at (axis cs: 30,2) {$\Delta X$};
        \end{axis}
        \end{tikzpicture}
        \caption{Mesh for a 1D problem}
        \label{fig:fdm_1d_mesh}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.5\textwidth}
        \centering
        \begin{tikzpicture}
        \centering
        \begin{axis}[
        axis lines = left,
        xtick pos=left,
        ytick pos=left,
        xlabel={$X$},
        ylabel={$Y$},
        xmin=0, xmax=105,
        ymin=0, ymax=130,
        xtick={0,20,40,60,80,100},
        xticklabels={$X_{0}$, $X_{1}$, , , $X_{L-1}$, $X_{L}$},
        ytick={0,20,40,60,80,100,120},
        yticklabels={$Y_{0}$, $Y_{1}$, , , , $Y_{M-1}$, $Y_{M}$},
        ymajorgrids=true,
        xmajorgrids=true,
        grid style=dashed,
        ]
        \addplot[
        only marks,
        color=black,
        mark=*,
        ]
        coordinates {
            (0, 0)(0, 20)(0,40)(0,60)(0,80)(0,100)(0,120)
            
            (20, 0)(20, 20)(20,40)(20,60)(20,80)(20,100)(20,120)
            
            (40, 0)(40, 20)(40,40)(40,60)(40,80)(40,100)(40,120)
            
            (60, 0)(60, 20)(60,40)(60,60)(60,80)(60,100)(60,120)
            
            (80, 0)(80, 20)(80,40)(80,60)(80,80)(80,100)(80,120)
            
            (100, 0)(100, 20)(100,40)(100,60)(100,80)(100,100)(100,120)
            
        };
        \addplot +[mark=none, color=gray] coordinates {(20, 60) (20, 80)};
        \node[] at (axis cs: 14,70) {$\Delta Y$};
        \addplot +[mark=none, color=gray] coordinates {(20, 60) (40, 60)};
        \node[] at (axis cs: 30,54) {$\Delta X$};
        \end{axis}
        \end{tikzpicture}
        \caption{Mesh for a 2D problem}
        \label{fig:fdm_2d_mesh}
    \end{minipage}  
\end{figure}
    
\medskip
\textbf{scaled = 0.8}
\medskip

\begin{figure}[h]
    \begin{minipage}[b]{0.5\textwidth}
        \centering
        \begin{tikzpicture}[scale=0.8] % <<<<<< changed
        \centering
        \begin{axis}[
        height = 3 cm,
        width = 7 cm,
        axis lines = left,
        xtick pos=left,
        hide y axis,
        xlabel={$X$},
        xmin=0, xmax=105,
        ymin=-3, ymax=3,
        enlarge y limits = false,
        xtick={0,20,40,60,80,100},
        xticklabels={$X_{0}$, $X_{1}$, , , $X_{L-1}$, $X_{L}$}
        ]
        \addplot[
        only marks,
        color=black,
        mark=*,
        ]
        coordinates {
            (0, 0)(20, 0)(40, 0)(60, 0)(80, 0)(100, 0) 
        };
        \addplot +[mark=none, color=gray] coordinates {(20, 0) (40, 0)};
        \addplot +[mark=none, color=black] coordinates {(0, -1) (0, 1)(100, 1) (100, -1) (0, -1)};
        \node[] at (axis cs: 30,2) {$\Delta X$};
        \end{axis}
        \end{tikzpicture}
        \caption{Mesh for a 1D problem}
        \label{fig:fdm_1d_meshi}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.5\textwidth}
        \centering
        \begin{tikzpicture}[scale=0.8] % <<<<<< changed
        \centering
        \begin{axis}[
        axis lines = left,
        xtick pos=left,
        ytick pos=left,
        xlabel={$X$},
        ylabel={$Y$},
        xmin=0, xmax=105,
        ymin=0, ymax=130,
        xtick={0,20,40,60,80,100},
        xticklabels={$X_{0}$, $X_{1}$, , , $X_{L-1}$, $X_{L}$},
        ytick={0,20,40,60,80,100,120},
        yticklabels={$Y_{0}$, $Y_{1}$, , , , $Y_{M-1}$, $Y_{M}$},
        ymajorgrids=true,
        xmajorgrids=true,
        grid style=dashed,
        ]
        \addplot[
        only marks,
        color=black,
        mark=*,
        ]
        coordinates {
            (0, 0)(0, 20)(0,40)(0,60)(0,80)(0,100)(0,120)
            
            (20, 0)(20, 20)(20,40)(20,60)(20,80)(20,100)(20,120)
            
            (40, 0)(40, 20)(40,40)(40,60)(40,80)(40,100)(40,120)
            
            (60, 0)(60, 20)(60,40)(60,60)(60,80)(60,100)(60,120)
            
            (80, 0)(80, 20)(80,40)(80,60)(80,80)(80,100)(80,120)
            
            (100, 0)(100, 20)(100,40)(100,60)(100,80)(100,100)(100,120)
            
        };
        \addplot +[mark=none, color=gray] coordinates {(20, 60) (20, 80)};
        \node[] at (axis cs: 14,70) {$\Delta Y$};
        \addplot +[mark=none, color=gray] coordinates {(20, 60) (40, 60)};
        \node[] at (axis cs: 30,54) {$\Delta X$};
        \end{axis}
        \end{tikzpicture}
        \caption{Mesh for a 2D problem}
        \label{fig:fdm_2d_meshi}
    \end{minipage}
\end{figure}

    
\end{document}

答案2

它可能会解决你的问题:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\begin{figure}[ht]
\pgfplotsset{width=0.98\linewidth,
             axis lines=left,
             xlabel=$X$,
             xtick={0,20,...,100},
             xticklabels={$X_{0}$, $X_{1}$, , , $X_{L-1}$, $X_{L}$},
             enlarge y limits = false
             }
\begin{minipage}[b]{0.46\textwidth}
\centering
    \begin{tikzpicture}
\begin{axis}[
    height = 3 cm,
    hide y axis,
    xmin=0, xmax=105,
    ymin=-3, ymax=3,    
]
\addplot[only marks]
    coordinates {
    (0, 0)(20, 0)(40, 0)(60, 0)(80, 0)(100, 0)
    };
\addplot +[mark=none, color=gray] coordinates {(20, 0) (40, 0)}
    node[midway, above, black]  {$\Delta X$};
\addplot +[mark=none, color=black] coordinates {(0, -1) (0, 1)(100, 1) (100, -1) (0, -1)};

\end{axis}
\end{tikzpicture}
    \caption{Mesh for a 1D problem}
    \label{fig:fdm_1d_mesh}
\end{minipage}%
%
\begin{minipage}[b]{0.54\textwidth}
\centering
    \begin{tikzpicture}
\begin{axis}[
    ylabel={$Y$},
    xmin=0, xmax=105,
    ymin=0, ymax=130,
    ytick={0,20,...,120},
    yticklabels={$Y_{0}$, $Y_{1}$, , , , $Y_{M-1}$, $Y_{M}$},
    grid,
    grid style=dashed,
]
\addplot[only marks]
    coordinates {
    (0, 0)(0, 20)(0,40)(0,60)(0,80)(0,100)(0,120)
    (20, 0)(20, 20)(20,40)(20,60)(20,80)(20,100)(20,120)
    (40, 0)(40, 20)(40,40)(40,60)(40,80)(40,100)(40,120)
    (60, 0)(60, 20)(60,40)(60,60)(60,80)(60,100)(60,120)
    (80, 0)(80, 20)(80,40)(80,60)(80,80)(80,100)(80,120)
    (100, 0)(100, 20)(100,40)(100,60)(100,80)(100,100)(100,120)
    };
\addplot +[mark=none, color=gray] coordinates {(20, 60) (20, 80)} 
        node[midway, left,black]    {$\Delta Y$};
\addplot +[mark=none, color=gray] coordinates {(20, 60) (40, 60)}
        node[midway,below,black]    {$\Delta X$};
\end{axis}
\end{tikzpicture}
    \caption{Mesh for a 2D problem}
    \label{fig:fdm_2d_mesh}
\end{minipage}
    \end{figure}
\end{document}

在此处输入图片描述

(红线显示文字边框)

相关内容