如何将图形放在页面顶部?

How can I place a figure on top of the page?

我目前正在处理这段代码(这是一个简化版):

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
% Syntax:
% \DoublLine[half of the double line distance]{first node}{second node}{options line 1}{options line 2}
\newcommand\DoubleLine[5][4pt]{%
    \path(#2)--(#3)coordinate[at start](h1)coordinate[at end](h2);
    \draw[#4]($(h1)!#1!90:(h2)$)--($(h2)!#1!-90:(h1)$); 
    % node [midway, above=1pt, fill=none] {3};
    \draw[#5]($(h1)!#1!-90:(h2)$)--($(h2)!#1!90:(h1)$); 
    % node [midway, below=1pt, fill=none] {3};
    }
\begin{figure}[h]
    \begin{tikzpicture}[myn/.style={very thick,draw,inner sep=0.25cm,outer sep=3pt}]
    \scalebox{0.5}{
\centering
     % place nodes
\node[myn]  (a) at (2,5) {Node 6};
    \node[myn]  (b) at  (4, 8)   {Node 12};
    \node[myn]  (c) at  (5, 5)  {Node 19};
    \node[myn]  (d) at  (5, 3)  {Node 20};
    \node[myn]  (e) at  (7.5,5)  {Node 18};
    \node[myn]  (f) at  (7.5,10)  {Node 10};
\node[myn]  (g) at  (10,3)  {Node 4};
    \node[myn]  (h) at  (10,5)  {Node 2};
    \node[myn]  (i) at  (10,8)  {Node 13};
    \node[myn]  (j) at  (10,10)  {Node 14};
    \node[myn]  (k) at  (13,5)  {Node 21};
    \node[myn]  (l) at  (12,7)  {Node 1};
\node[myn]  (m) at  (12,10)  {Node 16};
    \node[myn]  (n) at  (15.5,5)  {Node 3};
    \node[myn]  (o) at  (13,12)  {Node 8};
    \node[myn]  (p) at  (16,3)  {Node 5};
    \node[myn]  (q) at  (16,7)  {Node 9};
    \node[myn]  (r) at  (7.5,3)  {Node 11};
\node[myn]  (s) at  (11,1){Node 7};
    \node[myn]  (t) at  (12,-1){Node 17};
    \node[myn]  (u) at  (13,-3){Node 22};
    \node[myn]  (v) at  (7.5,-1){Node 15};     

%Single line orange
\draw[edge][color=orange, very thick] (i)--(j);

%Single line orange 
\draw[edge][color=orange, very thick] (n)--(q);
\draw[edge][color=orange, very thick] (h)--(d);

%double line orange
    \DoubleLine{o}{m}{-,very thick,cyan}{-,very thick,orange};
    \DoubleLine{i}{m}{-,very thick,cyan}{-,very thick,orange};
    

    
}
    \end{tikzpicture}
    \caption{Line plan: Model A on Set RL}
    \label{fig:Line plan Model A on Set RL}
\end{figure}
\end{document}

图片显示在页面中间,甚至没有居中。由于我是乳胶的初学者,我想知道这是如何工作的?我需要图片位于页面顶部并居中。

我尝试了 [h] 和 [t] 以及 \vspace*{3in},但它不起作用。

几个问题:

  • 你的图太大了,里面有很多白点space 是由下面几点提到的一些问题造成的。您可以在日志文件中看到有关 overfull box 的警告。因此它不能根据您的 [t] 浮动说明符

    放置
  • 在 tikz 图片中使用 \centering\scalebox 没有任何意义。如果想让图片居中,在tikzpicture之前使用

  • 不要对包含文本的元素使用 \scalebox

  • tikz 有自己的扩展命令

  • 如果你想让一个图形在页面的顶部,页面实际上需要一些文字

最后:

  • 代码不会 运行 如果它抛出错误消息! Latex only 语法检查文档的其余部分,不一定产生合理的输出。永远不要忽略错误消息。

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
% Syntax:
% \DoublLine[half of the double line distance]{first node}{second node}{options line 1}{options line 2}
\newcommand\DoubleLine[5][4pt]{%
    \path(#2)--(#3)coordinate[at start](h1)coordinate[at end](h2);
    \draw[#4]($(h1)!#1!90:(h2)$)--($(h2)!#1!-90:(h1)$); 
    % node [midway, above=1pt, fill=none] {3};
    \draw[#5]($(h1)!#1!-90:(h2)$)--($(h2)!#1!90:(h1)$); 
    % node [midway, below=1pt, fill=none] {3};
    }
    
some text
    
\begin{figure}[t]
\centering
\begin{tikzpicture}[scale=0.5,transform shape,myn/.style={very thick,draw,inner sep=0.25cm,outer sep=3pt}]
\node[myn]  (a) at (2,5) {Node 6};
    \node[myn]  (b) at  (4, 8)   {Node 12};
    \node[myn]  (c) at  (5, 5)  {Node 19};
    \node[myn]  (d) at  (5, 3)  {Node 20};
    \node[myn]  (e) at  (7.5,5)  {Node 18};
    \node[myn]  (f) at  (7.5,10)  {Node 10};
\node[myn]  (g) at  (10,3)  {Node 4};
    \node[myn]  (h) at  (10,5)  {Node 2};
    \node[myn]  (i) at  (10,8)  {Node 13};
    \node[myn]  (j) at  (10,10)  {Node 14};
    \node[myn]  (k) at  (13,5)  {Node 21};
    \node[myn]  (l) at  (12,7)  {Node 1};
\node[myn]  (m) at  (12,10)  {Node 16};
    \node[myn]  (n) at  (15.5,5)  {Node 3};
    \node[myn]  (o) at  (13,12)  {Node 8};
    \node[myn]  (p) at  (16,3)  {Node 5};
    \node[myn]  (q) at  (16,7)  {Node 9};
    \node[myn]  (r) at  (7.5,3)  {Node 11};
\node[myn]  (s) at  (11,1){Node 7};
    \node[myn]  (t) at  (12,-1){Node 17};
    \node[myn]  (u) at  (13,-3){Node 22};
    \node[myn]  (v) at  (7.5,-1){Node 15};     

%Single line orange
\draw[][color=orange, very thick] (i)--(j);

%Single line orange 
\draw[][color=orange, very thick] (n)--(q);
\draw[][color=orange, very thick] (h)--(d);

%double line orange
    \DoubleLine{o}{m}{-,very thick,cyan}{-,very thick,orange};
    \DoubleLine{i}{m}{-,very thick,cyan}{-,very thick,orange};
    \end{tikzpicture}
    \caption{Line plan: Model A on Set RL}
    \label{fig:Line plan Model A on Set RL}
\end{figure}
\end{document}