如何在 tikz 中校准水平线

如何在 tikz 中校准水平线

在下面的 tikz 代码中,我想校准水平线从 0 到 12。不知怎的,我没能做到。我只能校准 (0 1, 2, ..., 12) 线的左半部分。如能得到任何帮助,我将不胜感激。

\documentclass[11pt]{report}
\usepackage{enumerate,mdwlist}
\usepackage[usegeometry]{typearea}% load before geometry
\usepackage[a4paper,width=150mm,vmargin=21mm,bindingoffset=12mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{tikz-3dplot}
\usetikzlibrary{shapes.geometric, decorations.pathreplacing, matrix, angles, quotes, arrows, arrows.meta, datavisualization,cd}
\usetikzlibrary{through,calc,intersections}
\usepackage{pgfplots}
\usepackage{psfrag}
\pgfplotsset{width=5cm,compat=newest}
\usepgfplotslibrary{fillbetween}
\usepackage{filecontents}
\usepackage[rawfloats=true]{floatrow} 
\restylefloat{figure}     % to reduce spaces between images and text.

\KOMAoptions{paper=landscape,DIV=last}
\newgeometry{hmargin=2.5cm,top=15mm,bottom=15mm,height=150mm,includehead}

\begin{document}
\tikzstyle{block0} = [rectangle, draw, fill=yellow!100, text width=4.7em, text centered, node distance=1.5cm, minimum height=1.0cm]   
\tikzstyle{block1} = [rectangle, draw, fill=green!1000,text width=4.5em, text centered, rounded corners, node distance= 1.5cm, minimum height=1.0cm]  
\tikzstyle{block2} = [rectangle, draw, fill=red!100, text width=10em, text centered, rounded corners, node distance=1.22cm, minimum width=5cm, minimum height=4cm]  
\tikzstyle{block3} = [rectangle, draw, fill=orange!100, text width=5cm, text centered, rounded corners, node distance=1.25cm, minimum width=5cm, minimum height=4cm]  
\tikzstyle{block4} = [rectangle, draw, fill=yellow!100, text width=4.5cm, text centered, rounded corners, node distance=1.25cm, minimum width=4.5cm, minimum height=4cm]  
\tikzstyle{block5} = [rectangle, draw, fill=green!100, text width=5cm, text centered, rounded corners, node distance=1.25cm, minimum width=5cm, minimum height=4cm]  
\tikzstyle{block6} = [rectangle, draw, fill=blue!100, text width=2cm, text centered, rounded corners, node distance=1.25cm, minimum width=3cm, minimum height=1cm]  
\begin{figure}[H]
\begin{tikzpicture}[node distance = 1.8cm, auto] % node distance is important to determines the space or the length of the arrow between different blocks.  
\node (pro1) [block0]{enviro check};
\node (pro2) [block1, below of=pro1]{register};
\node (pro3) [block2, right of=pro2, xshift=2.3cm,yshift=-1.0cm]{session1};
\node (pro4) [block3, right of=pro3, xshift=3.9cm,yshift=-2.0cm]{session2};
\node (pro5) [block4, below of=pro4, xshift=5.0cm,yshift=-0.5cm]{session3};
\node (pro6) [block5, below of=pro5, xshift=5.0cm,yshift=-0.5cm]{session4};
\node (pro7) [block6, below of=pro6, xshift=4.1cm,yshift=-1.2cm]{closing};

\draw[latex-latex] (0,-12.0) -- (24.0,-12.0) ; %for the axis
\foreach \x in  {0,2,4,6,8,10,12,14,16,18,20,22,24} % for the vertical lines
    \draw[shift={(\x,-12.0)},color=black] (0pt,6pt) -- (0pt,-6pt);
    \foreach \x in {0,1,2,3,4,5,6,7,8,9,10,11,12} % for the numbers
    \draw[shift={(\x,-12.0)},color=black] (0pt,0pt) -- (0pt,-6pt) node[below] 
{$\x$};
\end{tikzpicture}
\end{figure}
\end{document}

答案1

\documentclass[tikz, border=1cm]{standalone}
\tikzset{
block0/.style={rectangle, draw, fill=yellow!100, text width=4.7em, text centered, node distance=1.5cm, minimum height=1.0cm},
block1/.style={rectangle, draw, fill=green!1000,text width=4.5em, text centered, rounded corners, node distance= 1.5cm, minimum height=1.0cm},  
block2/.style={rectangle, draw, fill=red!100, text width=10em, text centered, rounded corners, node distance=1.22cm, minimum width=5cm, minimum height=4cm},  
block3/.style={rectangle, draw, fill=orange!100, text width=5cm, text centered, rounded corners, node distance=1.25cm, minimum width=5cm, minimum height=4cm},  
block4/.style={rectangle, draw, fill=yellow!100, text width=4.5cm, text centered, rounded corners, node distance=1.25cm, minimum width=4.5cm, minimum height=4cm},  
block5/.style={rectangle, draw, fill=green!100, text width=5cm, text centered, rounded corners, node distance=1.25cm, minimum width=5cm, minimum height=4cm},  
block6/.style={rectangle, draw, fill=blue!100, text width=2cm, text centered, rounded corners, node distance=1.25cm, minimum width=3cm, minimum height=1cm},  
}

\begin{document}
\begin{tikzpicture}[node distance=1.8cm, auto]
\node (pro1) [block0]{enviro check};
\node (pro2) [block1, below of=pro1]{register};
\node (pro3) [block2, right of=pro2, xshift=2.3cm, yshift=-1.0cm]{session1};
\node (pro4) [block3, right of=pro3, xshift=3.9cm, yshift=-2.0cm]{session2};
\node (pro5) [block4, below of=pro4, xshift=5.0cm, yshift=-0.5cm]{session3};
\node (pro6) [block5, below of=pro5, xshift=5.0cm, yshift=-0.5cm]{session4};
\node (pro7) [block6, below of=pro6, xshift=4.1cm, yshift=-1.2cm]{closing};
\draw[latex-latex] (0,-12.0) -- (24.0,-12.0);
\foreach \x in  {0,2,4,6,8,10,12,14,16,18,20,22,24} 
\draw[shift={(\x,-12.0)},color=black] (0pt,6pt) -- (0pt,-6pt);
\foreach \x in {0,1,2,3,4,5,6,7,8,9,10,11,12}
\draw[shift={(2*\x,-12.0)}] (0pt,0pt) -- (0pt,-6pt) node[below] {$\x$};
\end{tikzpicture}
\end{document}

彩色盒子和数字线

相关内容