在多列乳胶文档中插入多个 TikZ 图形时,文本流中断

在多列乳胶文档中插入多个 TikZ 图形时,文本流中断

我在将 TikZ 放入多列乳胶中而不引入不需要的空格时遇到了麻烦。

main.tex

\documentclass[10pt]{article}

% Packages
\usepackage{multicol,caption}
\usepackage{graphicx}
\usepackage{float}
\usepackage{wrapfig}

\usepackage{lipsum}

\newenvironment{Figure}
  {\par\medskip\noindent\minipage{\linewidth}}
  {\endminipage\par\medskip}

\newcommand\myfigure[1]{%
\medskip\noindent\begin{minipage}{\columnwidth}
\centering%
#1%
%figure,caption, and label go here
\end{minipage}\medskip}

\usepackage{titlesec}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}

\titleclass{\subsubsubsection}{straight}[\subsection]

\newcounter{subsubsubsection}[subsubsection]
\renewcommand\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}}
\renewcommand\theparagraph{\thesubsubsubsection.\arabic{paragraph}} % optional; useful if paragraphs are to be numbered

\titleformat{\subsubsubsection}
  {\normalfont\normalsize\bfseries}{\thesubsubsubsection}{1em}{}
\titlespacing*{\subsubsubsection}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{5}{\z@}%
  {3.25ex \@plus1ex \@minus.2ex}%
  {-1em}%
  {\normalfont\normalsize\bfseries}}
\renewcommand\subparagraph{\@startsection{subparagraph}{6}{\parindent}%
  {3.25ex \@plus1ex \@minus .2ex}%
  {-1em}%
  {\normalfont\normalsize\bfseries}}
\def\toclevel@subsubsubsection{4}
\def\toclevel@paragraph{5}

\def\toclevel@paragraph{6}
\def\l@subsubsubsection{\@dottedtocline{4}{7em}{4em}}
\def\l@paragraph{\@dottedtocline{5}{10em}{5em}}
\def\l@subparagraph{\@dottedtocline{6}{14em}{6em}}
\makeatother
% Uses alphabets instead of numbers for the subsubsubsection
\def\thesubsubsubsection{\alph{subsubsubsection}}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, arrows.meta}
\usepackage{makecell}
\tikzstyle{startstop} = [draw, rounded rectangle, minimum width=3cm, minimum height=1cm, text width=3cm, text centered, draw=black]
\tikzstyle{object} = [draw, trapezium, trapezium left angle=70, trapezium right angle=-70, minimum width=3cm, minimum height=1cm, text centered, draw=black]
\tikzstyle{process} = [draw, rectangle, minimum width=3cm, minimum height=1cm, text width=3cm, text centered, draw=black]
\tikzstyle{arrow} = [thick,->,>=Triangle]

\usepackage{subfiles}
\providecommand{\main}{.}
\geometry{a4paper, margin = 1in}


% Document
\begin{document}

  \begin{multicols}{2}

  \subfile{sample/sample.tex}

  \bibliography{main}

  \end{multicols}

\end{document}

看上去怎么样sample.tex

Figure解决方案:

% Preamble
\providecommand{\main}{..}
\documentclass[\main/main.tex]{subfiles}

% Packages

% Document
\begin{document}

  \section{Section}

  \lipsum[1][1-2]

  \subsection{Subsection}

  \lipsum[2][2-5]

  \subsubsection{Subsubsection}

  \lipsum[3][1-3]

  \subsubsubsection{subsubsubsection}

  \lipsum[3-4][1-4]

  \begin{Figure}
    \centering
    \begin{tikzpicture}[node distance=2cm]
      \node(start)[startstop]{Start};
      \node(nd1)[object, below of=start]{Node1};
      \node(nd2)[process, below of=nd1]{\makecell[c]{Node \\ 2}};
      \node(nd3)[process, below of=nd2]{Node3};
      \node(nd4)[object, below of=nd3]{\makecell[c]{Node4}};
      \node(end)[startstop, below of=nd4]{End};

      \draw[arrow](start)--(nd1);
      \draw[arrow](nd1)--(nd2);
      \draw[arrow](nd2)--(nd3);
      \draw[arrow](nd3)--(nd4);
      \draw[arrow](nd4)--(end);
    \end{tikzpicture}
    \captionof{figure}{Some text describing the Figure}
  \end{Figure}

  \lipsum[4-6]

  \begin{Figure}
    \centering
    \begin{tikzpicture}[node distance=2cm]
      \node(start)[startstop]{Start};
      \node(nd1)[object, below of=start]{Node1};
      \node(nd2)[process, below of=nd1]{\makecell[c]{Node \\ 2}};
      \node(nd3)[process, below of=nd2]{Node3};
      \node(nd4)[object, below of=nd3]{\makecell[c]{Node4}};
      \node(end)[startstop, below of=nd4]{End};

      \draw[arrow](start)--(nd1);
      \draw[arrow](nd1)--(nd2);
      \draw[arrow](nd2)--(nd3);
      \draw[arrow](nd3)--(nd4);
      \draw[arrow](nd4)--(end);
    \end{tikzpicture}
    \captionof{figure}{Some text describing the Figure}
  \end{Figure}

  \lipsum[6-7]

\end{document}

此处建议的解决方案不会按预期换行,并且在段落之间留下大量空白,如紫色箭头所示。类似方法也不起作用并显示相同的空白。 段落之间的空白

图[H]方法:

% Same as before

  \begin{figure}[H]
    \centering
    \begin{tikzpicture}[node distance=2cm]
      \node(start)[startstop]{Start};
      \node(nd1)[object, below of=start]{Node1};
      \node(nd2)[process, below of=nd1]{\makecell[c]{Node \\ 2}};
      \node(nd3)[process, below of=nd2]{Node3};
      \node(nd4)[object, below of=nd3]{\makecell[c]{Node4}};
      \node(end)[startstop, below of=nd4]{End};

      \draw[arrow](start)--(nd1);
      \draw[arrow](nd1)--(nd2);
      \draw[arrow](nd2)--(nd3);
      \draw[arrow](nd3)--(nd4);
      \draw[arrow](nd4)--(end);
    \end{tikzpicture}
    \caption{Some text describing the figure}
  \end{figure}

  \lipsum[4-6]

  \begin{figure}[H]
    \centering
    \begin{tikzpicture}[node distance=2cm]
      \node(start)[startstop]{Start};
      \node(nd1)[object, below of=start]{Node1};
      \node(nd2)[process, below of=nd1]{\makecell[c]{Node \\ 2}};
      \node(nd3)[process, below of=nd2]{Node3};
      \node(nd4)[object, below of=nd3]{\makecell[c]{Node4}};
      \node(end)[startstop, below of=nd4]{End};

      \draw[arrow](start)--(nd1);
      \draw[arrow](nd1)--(nd2);
      \draw[arrow](nd2)--(nd3);
      \draw[arrow](nd3)--(nd4);
      \draw[arrow](nd4)--(end);
    \end{tikzpicture}
    \caption{Some text describing the figure}
  \end{figure}

  \lipsum[6-7]

  \begin{figure}[H]
    \centering
    \begin{tikzpicture}[node distance=2cm]
      \node(start)[startstop]{Start};
      \node(nd1)[object, below of=start]{Node1};
      \node(nd2)[process, below of=nd1]{\makecell[c]{Node \\ 2}};
      \node(nd3)[process, below of=nd2]{Node3};
      \node(nd4)[object, below of=nd3]{\makecell[c]{Node4}};
      \node(end)[startstop, below of=nd4]{End};

      \draw[arrow](start)--(nd1);
      \draw[arrow](nd1)--(nd2);
      \draw[arrow](nd2)--(nd3);
      \draw[arrow](nd3)--(nd4);
      \draw[arrow](nd4)--(end);
    \end{tikzpicture}
    \caption{Some text describing the figure}
  \end{figure}

% Same as before

我也试过此方法涉及float包,但有相同的问题。它可能适用于单个图形,但多个图形会破坏它,因为它会消除图形“浮动”的能力,如果我对figure[H]工作原理的理解是正确的。 在此处输入图片描述

wrapfigure方法:

% Same as before

  \begin{wrapfigure}{l}{\linewidth}
    \centering
      \begin{tikzpicture}[node distance=2cm]
      \node(start)[startstop]{Start};
      \node(nd1)[object, below of=start]{Node1};
      \node(nd2)[process, below of=nd1]{\makecell[c]{Node \\ 2}};
      \node(nd3)[process, below of=nd2]{Node3};
      \node(nd4)[object, below of=nd3]{\makecell[c]{Node4}};
      \node(end)[startstop, below of=nd4]{End};

      \draw[arrow](start)--(nd1);
      \draw[arrow](nd1)--(nd2);
      \draw[arrow](nd2)--(nd3);
      \draw[arrow](nd3)--(nd4);
      \draw[arrow](nd4)--(end);
    \end{tikzpicture}
    \caption{Some text describing the figure}
  \end{wrapfigure}

  \lipsum[4-6]

  \begin{wrapfigure}{l}{1.0\linewidth}
    \centering
      \begin{tikzpicture}[node distance=2cm]
      \node(start)[startstop]{Start};
      \node(nd1)[object, below of=start]{Node1};
      \node(nd2)[process, below of=nd1]{\makecell[c]{Node \\ 2}};
      \node(nd3)[process, below of=nd2]{Node3};
      \node(nd4)[object, below of=nd3]{\makecell[c]{Node4}};
      \node(end)[startstop, below of=nd4]{End};

      \draw[arrow](start)--(nd1);
      \draw[arrow](nd1)--(nd2);
      \draw[arrow](nd2)--(nd3);
      \draw[arrow](nd3)--(nd4);
      \draw[arrow](nd4)--(end);
    \end{tikzpicture}
    \caption{Some text describing the figure}
  \end{wrapfigure}

% Same as before

如果想要全宽,则无法像 Overleaf 中那样对图形进行换行。它在文档的开头和结尾处也会表现得很怪异。 在此处输入图片描述

这些图不必完全位于它们被调用的位置,但位于同一页或同一页左右也是可以接受的。任何解决方案都将不胜感激。

答案1

图像似乎太大了,以至于无法将它们放在同一页上,紧接着插入文本的位置。如果您允许图片浮动,那么第二幅图像将在下一页尽可能靠近第一幅图像,即在下一页的顶部。

如果允许(容忍?)的话,那么很容易实现以下结果:

在此处输入图片描述

\documentclass[twocolumn]{article}
% Packages
\usepackage[a4paper, margin = 1in]{geometry}
\usepackage{caption}
\usepackage{graphicx}

\usepackage{titlesec}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}

\titleclass{\subsubsubsection}{straight}[\subsection]

\newcounter{subsubsubsection}[subsubsection]
\renewcommand\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}}
\renewcommand\theparagraph{\thesubsubsubsection.\arabic{paragraph}} % optional; useful if paragraphs are to be numbered

\titleformat{\subsubsubsection}
  {\normalfont\normalsize\bfseries}{\thesubsubsubsection}{1em}{}
\titlespacing*{\subsubsubsection}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{5}{\z@}%
  {3.25ex \@plus1ex \@minus.2ex}%
  {-1em}%
  {\normalfont\normalsize\bfseries}}
\renewcommand\subparagraph{\@startsection{subparagraph}{6}{\parindent}%
  {3.25ex \@plus1ex \@minus .2ex}%
  {-1em}%
  {\normalfont\normalsize\bfseries}}
\def\toclevel@subsubsubsection{4}
\def\toclevel@paragraph{5}

\def\toclevel@paragraph{6}
\def\l@subsubsubsection{\@dottedtocline{4}{7em}{4em}}
\def\l@paragraph{\@dottedtocline{5}{10em}{5em}}
\def\l@subparagraph{\@dottedtocline{6}{14em}{6em}}
\makeatother
% Uses alphabets instead of numbers for the subsubsubsection
\def\thesubsubsubsection{\alph{subsubsubsection}}
        
        

\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                positioning,
                shapes.geometric}
\tikzset{
               > = Triangle,
     base/.style = {draw, minimum height=1cm, text width=3cm, align=center},
startstop/.style = {base, rounded corners},
   object/.style = {base, trapezium, trapezium stretches body,
                    trapezium left angle=70, trapezium right angle=110},
  process/.style = {base},
    arrow/.style = {thick,->}
        }
\usepackage{lipsum}


\begin{document}

\section{Section}
\lipsum[1][1-2]

\subsection{Subsection}
\lipsum[2][2-5]

\subsubsection{Subsubsection}
\lipsum[3][1-3]

\subsubsubsection{subsubsubsection}
\lipsum[3-4][1-4]
\textbf{The first image is inserted here}

    \begin{figure}[htb]
    \centering
    \begin{tikzpicture}[
node distance = 9mm,
  start chain = going below
                        ]
    \begin{scope}[nodes={on chain, join=by arrow}]
\node   [startstop] {Start};
\node   [object]    {Node1};
\node   [process]   {Node \\ 2};
\node   [process]   {Node3};
\node   [object]    {Node4};
\node   [startstop] {End};
    \end{scope}
    \end{tikzpicture}
\caption{Some text describing the Figure}
\label{fig:1}
    \end{figure}

\lipsum[4-6]
\textbf{The second image is inserted here}

    \begin{figure}[ht]
    \centering
    \begin{tikzpicture}[
node distance = 9mm,
  start chain = going below
                        ]
    \begin{scope}[nodes={on chain, join=by arrow}]
\node [startstop]   {Start};
\node [object]      {Node1};
\node   [process]   {Node \\ 2};
\node   [process]   {Node3};
\node   [object]    {Node4};
\node   [startstop] {End};
    \end{scope}
    \end{tikzpicture}
\caption{Some text describing the Figure}
\label{fig:2}
    \end{figure}

  \lipsum[6-7]

\textbf{The rest of article}

\end{document}

如果这是不可接受的,那么你没有太多选择可以做。其中可以做的有:

  • minimum height降低图像的高度,在所显示的图像中,可以通过减少节点之间的距离或减少节点并使用较小的字体大小来实现。
  • 将图片移至页面较早的位置,例如移至一个段落。在这种情况下,第一次提到此图片是在下一页。最终可以通过重新措辞此段落中的文本来解决此问题。例如:

在此处输入图片描述

% preamble as before
\begin{document}

\section{Section}
\lipsum[1][1-2]

\subsection{Subsection}
\lipsum[2][2-5]

\subsubsection{Subsubsection}
\lipsum[3][1-3]

\subsubsubsection{subsubsubsection}
\lipsum[3-4][1-4]
\textbf{The first image is inserted here}

    \begin{figure}[htb]
    \centering
    \begin{tikzpicture}[
node distance = 9mm,
  start chain = going below
                        ]
    \begin{scope}[nodes={on chain, join=by arrow}]
\node   [startstop] {Start};
\node   [object]    {Node1};
\node   [process]   {Node \\ 2};
\node   [process]   {Node3};
\node   [object]    {Node4};
\node   [startstop] {End};
    \end{scope}
    \end{tikzpicture}
\caption{Some text describing the Figure}
\label{fig:1}
    \end{figure}

\lipsum[4-5] %<---
\textbf{The second image is inserted in text earlier}

    \begin{figure}[ht]
    \centering
    \begin{tikzpicture}[
node distance = 9mm,
  start chain = going below
                        ]
    \begin{scope}[nodes={on chain, join=by arrow}]
\node [startstop]   {Start};
\node [object]      {Node1};
\node   [process]   {Node \\ 2};
\node   [process]   {Node3};
\node   [object]    {Node4};
\node   [startstop] {End};
    \end{scope}
    \end{tikzpicture}
\caption{Some text describing the Figure}
\label{fig:2}
    \end{figure}
\textbf{Rephrase paragraph, that figure 2 will mentioned earlier in paragraph, for example \emph{here}}
\lipsum[5] 
\textbf{Originally was here}

\lipsum[6-7]
\textbf{The rest of article}

\end{document}

题外话:我擅自缩短了你的tikzpicture代码。

答案2

我有点时间要打发,所以我想我会说明一下我的旧解决方案在您的任何但几乎可以工作的示例上。由于页面上没有足够的空间容纳第二个图形,因此它将被移动到下一页。

主文件(test5):

\documentclass[10pt]{article}

% Packages
\usepackage{geometry}% added
\usepackage{multicol,caption}
\usepackage{graphicx}
\usepackage{float}
\usepackage{wrapfig}

\usepackage{lipsum}

\newenvironment{Figure}
  {\par\medskip\noindent\minipage{\linewidth}}
  {\endminipage\par\medskip}

\newcommand\myfigure[1]{%
\medskip\noindent\begin{minipage}{\columnwidth}
\centering%
#1%
%figure,caption, and label go here
\end{minipage}\medskip}

\usepackage{titlesec}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}

\titleclass{\subsubsubsection}{straight}[\subsection]

\newcounter{subsubsubsection}[subsubsection]
\renewcommand\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}}
\renewcommand\theparagraph{\thesubsubsubsection.\arabic{paragraph}} % optional; useful if paragraphs are to be numbered

\titleformat{\subsubsubsection}
  {\normalfont\normalsize\bfseries}{\thesubsubsubsection}{1em}{}
\titlespacing*{\subsubsubsection}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{5}{\z@}%
  {3.25ex \@plus1ex \@minus.2ex}%
  {-1em}%
  {\normalfont\normalsize\bfseries}}
\renewcommand\subparagraph{\@startsection{subparagraph}{6}{\parindent}%
  {3.25ex \@plus1ex \@minus .2ex}%
  {-1em}%
  {\normalfont\normalsize\bfseries}}
\def\toclevel@subsubsubsection{4}
\def\toclevel@paragraph{5}

\def\toclevel@paragraph{6}
\def\l@subsubsubsection{\@dottedtocline{4}{7em}{4em}}
\def\l@paragraph{\@dottedtocline{5}{10em}{5em}}
\def\l@subparagraph{\@dottedtocline{6}{14em}{6em}}
\makeatother
% Uses alphabets instead of numbers for the subsubsubsection
\def\thesubsubsubsection{\alph{subsubsubsection}}

\usepackage{tikz}
\usetikzlibrary{shapes, arrows, arrows.meta}
\usepackage{makecell}
% note: \tikxstyle obsolete
\tikzset{startstop/.style = {draw, rounded rectangle, minimum width=3cm, minimum height=1cm, text width=3cm, text centered, draw=black}}
\tikzset{object/.style = {draw, trapezium, trapezium left angle=70, trapezium right angle=-70, minimum width=3cm, minimum height=1cm, text centered, draw=black}}
\tikzset{process/.style = {draw, rectangle, minimum width=3cm, minimum height=1cm, text width=3cm, text centered, draw=black}}
\tikzset{arrow/.style = {thick,->,>=Triangle}}

\usepackage{subfiles}% 
\providecommand{\main}{.}
\geometry{a4paper, margin = 1in}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\newcommand{\split}[2]% #1 = text, #2 = insert
{\par\bgroup
  \setbox0=\vbox{\strut #1\strut}% measure height
  \sbox1{#2}% ditto
  \dimen0=\dimexpr \pagegoal-\pagetotal-\col@number\baselineskip\relax% fudge factor
  \dimen1=\pagegoal% compute height of one column
  \ifnum\col@number>1\relax
    \divide\dimen1 by \col@number
  \fi
  \advance\dimen1 by -\baselineskip% fudge factor
  \loop\ifdim\dimen0>\dimen1% space left in this column
    \advance\dimen0 by -\dimen1
  \repeat
  \dimen1=\dimexpr \ht1+\dp1+\textfloatsep\relax% space needed for insert
  \ifdim\dimen1>\dimen0
    \ifdim\ht0>\dimen0
      \setbox2=\vsplit0 to \dimen0
      \unvbox2
      \noindent\box1
      \vskip\textfloatsep
      \unvbox0
    \else% entire text will fit into column
      \unvbox0
      \vskip\textfloatsep% probably ignored
      \noindent\box1
      \vskip\textfloatsep
    \fi
  \else% insert will fit into column
    \vskip\intextsep
    \noindent\box1
    \vskip\intextsep
    \unvbox0
  \fi
\egroup\par}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document
\begin{document}

  \begin{multicols}{2}

  \subfile{test6}% filename changed

  %\bibliography{main}% no bib file

  \end{multicols}

\end{document}

子文件(test6):

% Preamble
\providecommand{\main}{..}
\documentclass[test5]{subfiles}% finlename change

% Packages

% Document
\begin{document}

  \section{Section}

  \lipsum[1][1-2]

  \subsection{Subsection}

  \lipsum[2][2-5]

  \subsubsection{Subsubsection}

  \lipsum[3][1-3]

  \subsubsubsection{subsubsubsection}

  \lipsum[3-4][1-4]

\split{\lipsum[4-6]}{%
  \begin{Figure}
    \centering
    \begin{tikzpicture}[node distance=2cm]
      \node(start)[startstop]{Start};
      \node(nd1)[object, below of=start]{Node1};
      \node(nd2)[process, below of=nd1]{\makecell[c]{Node \\ 2}};
      \node(nd3)[process, below of=nd2]{Node3};
      \node(nd4)[object, below of=nd3]{\makecell[c]{Node4}};
      \node(end)[startstop, below of=nd4]{End};

      \draw[arrow](start)--(nd1);
      \draw[arrow](nd1)--(nd2);
      \draw[arrow](nd2)--(nd3);
      \draw[arrow](nd3)--(nd4);
      \draw[arrow](nd4)--(end);
    \end{tikzpicture}
    \captionof{figure}{Some text describing the Figure}
  \end{Figure}}

\split{\lipsum[6-7]}{%
  \begin{Figure}
    \centering
    \begin{tikzpicture}[node distance=2cm]
      \node(start)[startstop]{Start};
      \node(nd1)[object, below of=start]{Node1};
      \node(nd2)[process, below of=nd1]{\makecell[c]{Node \\ 2}};
      \node(nd3)[process, below of=nd2]{Node3};
      \node(nd4)[object, below of=nd3]{\makecell[c]{Node4}};
      \node(end)[startstop, below of=nd4]{End};

      \draw[arrow](start)--(nd1);
      \draw[arrow](nd1)--(nd2);
      \draw[arrow](nd2)--(nd3);
      \draw[arrow](nd3)--(nd4);
      \draw[arrow](nd4)--(end);
    \end{tikzpicture}
    \captionof{figure}{Some text describing the Figure}
  \end{Figure}}

\end{document}

相关内容