使用 tikz 调整行/段落之间的间距

使用 tikz 调整行/段落之间的间距

我知道,当我包含 graphs/ 时tikz,LaTeX 首先会计算图表所需的空间。如果空间不足,它会将图表推到下一页。为了让第一页看起来更美好,它会自动设置行/段落之间的间距。有办法阻止这种情况吗?有些东西告诉我这是一个快速/简短的命令 :( 但我找不到它。正如您在图片中看到的,间距一点也不好。

谢谢。

另外,有人可以告诉我如何复制和粘贴我的 LaTeX 代码,以便它在“提问”框中清晰可见吗?谢谢。

在此处输入图片描述 在此处输入图片描述

\documentclass[twoside]{book}

\usepackage{ tikz, pgfplots}

\linespread{1.25}

\usepackage{lipsum}

\pagestyle{empty}
\usepackage{cancel}

\begin{document}

\section{LaTeX Spacing Issues}

\lipsum[1]

%\begin{example}
\textbf{Main Example:}
several texts and equations here. It seems that if there is not enough space for the graph, then LaTeX automatically adjust the space between lines/graphs. 

\[y = x\]
Another equation, 
\[y = x^2\]

\[
\begin{tikzpicture}[x=1cm,y=0.07cm]
  \def\xmin{0}
  \def\xmax{10}
  \def\ymin{0}
  \def\ymax{120}

  % grid
\draw[style=help lines, ystep=10, xstep=1] (\xmin,\ymin) grid (\xmax,\ymax);

  % axes
  \draw[->] (\xmin,\ymin) -- coordinate (x axis mid) (\xmax+.5,\ymin) node[below] {$x$};
  \draw[->] (\xmin,\ymin) -- coordinate (y axis mid) (\xmin,\ymax+5) node[left] {$y$};

  % xticks and yticks
  \foreach \x in { 1, 2, ..., 10}
    \node at (\x, \ymin) [below] {\x};
  \foreach \y in {20, 40, ..., 120}
    \node at (\xmin,\y) [left] {\y};t
    \draw[scale=1,domain=0:10,smooth,variable=\x,blue, thick] plot ({\x},{12*\x});

\foreach \Point in {(1,12), (2,24), (3,36), (4,48), (5,60), (6,72), (7, 84)}{
    \node at \Point {\textbullet};
\node[below=.5cm] at (x axis mid) {Number of visitors};    
\node[left=.8cm,rotate=90] at (y axis mid) {Money taken };
}
\end{tikzpicture}
\]
%\end{example}

\subsection*{New section}
\lipsum[1]

答案1

该类默认book插入,flushbottom试图使每页的最后一行位于底部。这可以通过发出\raggedbottom前言来防止。

.
.
.
\raggedbottom
\begin{document}
.
.
.

在此处输入图片描述

但是,由于您要插入图片,因此最好不要在这种情况下使用显示数学模式。\[....\]您可以使用figure环境并让图片浮动,而不是使用。这样,您就可以利用 latex 放置图片的能力。此外,figure环境附带\caption宏,您可以使用它来对图片进行简短描述,此外,您还可以插入\label并在其他地方引用此图片。

\documentclass[twoside]{book}

\usepackage{ tikz, pgfplots}

\linespread{1.25}

\usepackage{lipsum}

\pagestyle{empty}
\usepackage{cancel}

\raggedbottom
\begin{document}

\section{LaTeX Spacing Issues}

\lipsum[1]

%\begin{example}
\textbf{Main Example:}
several texts and equations here. It seems that if there is not enough space for the graph, then LaTeX automatically adjust the space between lines/graphs.
%% no blank line be left here
\[y = x\]
Another equation,
\[y = x^2\]
%% no blank line be left here
\begin{figure}[htb]
\centering
\begin{tikzpicture}[x=1cm,y=0.07cm]
  \def\xmin{0}
  \def\xmax{10}
  \def\ymin{0}
  \def\ymax{120}

  % grid
\draw[style=help lines, ystep=10, xstep=1] (\xmin,\ymin) grid (\xmax,\ymax);

  % axes
  \draw[->] (\xmin,\ymin) -- coordinate (x axis mid) (\xmax+.5,\ymin) node[below] {$x$};
  \draw[->] (\xmin,\ymin) -- coordinate (y axis mid) (\xmin,\ymax+5) node[left] {$y$};

  % xticks and yticks
  \foreach \x in { 1, 2, ..., 10}
    \node at (\x, \ymin) [below] {\x};
  \foreach \y in {20, 40, ..., 120}
    \node at (\xmin,\y) [left] {\y};t
    \draw[scale=1,domain=0:10,smooth,variable=\x,blue, thick] plot ({\x},{12*\x});

\foreach \Point in {(1,12), (2,24), (3,36), (4,48), (5,60), (6,72), (7, 84)}{
    \node at \Point {\textbullet};
\node[below=.5cm] at (x axis mid) {Number of visitors};
\node[left=.8cm,rotate=90] at (y axis mid) {Money taken };
}
\end{tikzpicture}
\caption{This is a nice picture}
\end{figure}
%\end{example}

\subsection*{New section}
\lipsum[1]
\end{document}

在此处输入图片描述

相关内容