Tikz 图片出现在文档内错误的位置

Tikz 图片出现在文档内错误的位置

我没有发现任何关于此的问题,但我在将 Tikz 图片放入文档时遇到了问题。它包含在 Figure 环境中,并用于\centerfloat将其居中,因为它不是 Memoir,而是 Article 类,所以序言中有一些代码。

我在 MWE 中将图片添加到两个 Lorem Ipsum 之间,但在排版时,图片出现在两个 Lorem Ipsum 之前。发生了什么?我该如何解决?

\documentclass{article}
\usepackage{rotating}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,calc}
\usepackage{caption}

\makeatletter
\newcommand*{\centerfloat}{%
  \parindent \z@
  \leftskip \z@ \@plus 1fil \@minus \textwidth
  \rightskip\leftskip
  \parfillskip \z@skip}
\makeatother

\tikzset{
    every node/.style={align=center, fill=white, draw=black, thick, rectangle, outer sep=0mm, inner sep=0mm},
    rect/.style={minimum height=8mm},
    recv/.style={text width=2.5cm, rotate=90},
}

\begin{document}

    FIRST Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sit amet ante id augue faucibus maximus sit amet vel lacus. Suspendisse potenti. Nullam metus nunc, auctor vel rutrum sed, sollicitudin vitae ante. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. In ornare elit dui, sed aliquet erat pharetra ac. Nullam viverra ipsum tincidunt est cursus, at elementum neque congue. Aliquam tempor lorem ac eros mollis accumsan. Quisque vulputate consectetur ex at mattis. Ut aliquam, ligula at placerat elementum, lorem mauris convallis ante, vel faucibus nulla leo vel odio. Quisque nec ullamcorper ipsum.\\

\begin{figure}
    \centerfloat
\begin{tikzpicture}
    \node[rect, text width=4cm] (prop) at (0,0) {proposition};
    \node[rect, text width=12cm, left=0mm of prop, anchor=east] (ent) {entity};

\end{tikzpicture}
\caption{A caption}
\end{figure}

SECOND Nullam et efficitur justo. Donec sodales velit sit amet lorem varius tempus. Nulla vitae leo justo. Phasellus rhoncus egestas dui, in rutrum nisi ullamcorper sit amet. Aliquam eget imperdiet dolor. Morbi quis hendrerit erat. Nulla ornare purus ac sollicitudin dapibus.

\end{document} 

结果如下:

在此处输入图片描述

答案1

figure是专门用于希望图形浮动的情况。

要添加适当的标题,请使用captionof

尝试这个

\documentclass{article}
\usepackage{rotating}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,calc}
\usepackage{caption}

\makeatletter
\newcommand*{\centerfloat}{%
  \parindent \z@
  \leftskip \z@ \@plus 1fil \@minus \textwidth
  \rightskip\leftskip
  \parfillskip \z@skip}
\makeatother

\tikzset{
    every node/.style={align=center, fill=white, draw=black, thick, rectangle, outer sep=0mm, inner sep=0mm},
    rect/.style={minimum height=8mm},
    recv/.style={text width=2.5cm, rotate=90},
}

\begin{document}

    FIRST Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sit amet ante id augue faucibus maximus sit amet vel lacus. Suspendisse potenti. Nullam metus nunc, auctor vel rutrum sed, sollicitudin vitae ante. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. In ornare elit dui, sed aliquet erat pharetra ac. Nullam viverra ipsum tincidunt est cursus, at elementum neque congue. Aliquam tempor lorem ac eros mollis accumsan. Quisque vulputate consectetur ex at mattis. Ut aliquam, ligula at placerat elementum, lorem mauris convallis ante, vel faucibus nulla leo vel odio. Quisque nec ullamcorper ipsum.\\

\begin{centerfloat}
  \begin{tikzpicture}
    \node[rect, text width=4cm] (prop) at (0,0) {proposition};
    \node[rect, text width=12cm, left=0mm of prop, anchor=east] (ent) {entity};

\end{tikzpicture}}
\captionof{figure}{Sample picture}
\end{centerfloat}

SECOND Nullam et efficitur justo. Donec sodales velit sit amet lorem varius tempus. Nulla vitae leo justo. Phasellus rhoncus egestas dui, in rutrum nisi ullamcorper sit amet. Aliquam eget imperdiet dolor. Morbi quis hendrerit erat. Nulla ornare purus ac sollicitudin dapibus.

\end{document}

在此处输入图片描述

相关内容