在图片环境中制作水平轴

在图片环境中制作水平轴

嗨:我是乳胶新手,但我设法制作了下面的图片。我不知道该怎么做才能清楚地表明第一个框从 11:00 -11:01 运行,第二个框从 11:01-11:02 运行,第三个框从 11:02-11:03 运行,...第十个框从 11:09-11:10 运行。基本上,我想清楚地表明这些框实际上位于横跨 11:00-11:10 期间的水平轴上。如果我以无法实现或太容易的方式进行此操作,我愿意换成完全不同的方法,但我在制作乳胶图片方面更是新手,所以我不知道那是什么。起初我试图使用 tikz,但我发现它比我需要的更复杂,但也许我错了。非常感谢您的帮助。

\documentclass{article}

\begin{document}

\setlength{\unitlength}{0.5in}

\begin{picture}(5,5)
\put(-.25,4){\makebox(0.50,0.50){11:00-11:05}}        
\put(1.75,4){\framebox(0.5,0.5){$X_{1}^{*}$}}
\put(2.25,4){\framebox(0.5,0.5){$X_{2}^{*}$}}
\put(2.75,4){\framebox(0.5,0.5){$X_{3}^{*}$}}
\put(3.25,4){\framebox(0.5,0.5){$X_{4}^{*}$}}
\put(3.75,4){\framebox(0.5,0.5){$X_{5}^{*}$}}

\put(-.25,3){\makebox(0.50,0.50){11:01-11:06}}        
\put(2.25,3){\framebox(0.5,0.5){$X_{2}^{*}$}}
\put(2.75,3){\framebox(0.5,0.5){$X_{3}^{*}$}}
\put(3.25,3){\framebox(0.5,0.5){$X_{4}^{*}$}}
\put(3.75,3){\framebox(0.5,0.5){$X_{5}^{*}$}}
\put(4.25,3){\dashbox{0.05}(0.50,0.5){0}}

\put(-.25,2){\makebox(0.50,0.50){11:02-11:07}}        
\put(2.75,2){\framebox(0.5,0.5){$X_{3}^{*}$}}
\put(3.25,2){\framebox(0.5,0.5){$X_{4}^{*}$}}
\put(3.75,2){\framebox(0.5,0.5){$X_{5}^{*}$}}
\put(4.25,2){\dashbox{0.05}(0.50,0.5){0}}
\put(4.75,2){\dashbox{0.05}(0.50,0.5){0}}

\put(-.25,1){\makebox(0.50,0.50){11:03-11:08}}        
\put(3.25,1){\framebox(0.5,0.5){$X_{4}^{*}$}}
\put(3.75,1){\framebox(0.5,0.5){$X_{5}^{*}$}}
\put(4.25,1){\dashbox{0.05}(0.50,0.5){0}}
\put(4.75,1){\dashbox{0.05}(0.50,0.5){0}}
\put(5.25,1){\dashbox{0.05}(0.50,0.5){0}}

\put(-.25,0){\makebox(0.50,0.50){11:04-11:09}}        
\put(3.75,0){\framebox(0.5,0.5){$X_{5}^{*}$}}
\put(4.25,0){\dashbox{0.05}(0.50,0.5){0}}
\put(4.75,0){\dashbox{0.05}(0.50,0.5){0}}
\put(5.25,0){\dashbox{0.05}(0.50,0.5){0}}
\put(5.75,0){\dashbox{0.05}(0.50,0.5){0}}

\put(-.25,-1){\makebox(0.50,0.50){11:05-11:10}}        
\put(4.25,-1){\dashbox{0.05}(0.50,0.5){0}}
\put(4.75,-1){\dashbox{0.05}(0.50,0.5){0}}
\put(5.25,-1){\dashbox{0.05}(0.50,0.5){0}}
\put(5.75,-1){\dashbox{0.05}(0.50,0.5){0}}
\put(6.25,-1){\dashbox{0.05}(0.50,0.5){0}}

\end{picture}

\end{document}

结果: 结果

答案1

Z 版本:

\documentclass{article}

\usepackage{tikz} % needed for TikZ

\begin{document}
\begin{figure}[ht]
    \begin{tikzpicture}[
    squarednode/.style={draw=black, minimum size=9.9mm}, 
    % define a new node: black border and minimum size of 9.9mm
    y=1.5cm
    % set the y unit to 1.5cm to stretch the image in the y direction
    ]
    
    \newcommand{\absval}[1]{\ifnum#1<0 -\fi#1} % create new command \absval to get the absolut value of the argument
    \newcommand{\fullmin}[1]{\ifnum\absval{#1}<10 0\fi#1} % create new command \fullmin to get a leading 0 for numbers smaller than 10
    \newcommand{\nextstep}[1]{\pgfmathparse{int(#1+0.5)}\pgfmathresult} % create new command \nextstepto adding 0.5 to the argument
    
    % horizontal axis
    \draw[->] (0,0) -- (11,0) node[anchor=north] {min};
    
    %
    \foreach \x in {0,...,10} % \x = 0, 1, 2, ..., 10 
         {
    %help lines
        \draw [help lines, color=gray!30, dashed] (\x,0) -- (\x,6);
    %ticks
        \draw (\x,1pt) -- (\x,-3pt) node[anchor=north] {\fullmin{\x}};
        }
        
    % labels
    \foreach \y/\m/\mm in {5.5/00/05,4.5/01/06,3.5/02/07,2.5/03/08,1.5/04/09,0.5/05/10} % \y = 5.5, while \m = 00, while \mm = 05, ..., \y = 0.5, while \m = 05, while \mm = 10
        \draw (-2, \y) node{11:\m\,-\,11:\mm};
        
    %boxes
    \foreach \y [count=\yi from 0] in {5.5,...,1.5} % \y = 5.5, while \yi = 0, \y = 4.5, while \yi = 1, ..., \y = 1.5, while \yi = 4
    \foreach \x in {0.5+\yi,...,4.5} % \x = 0.5+\yi, ..., 4.5
        \draw (\x, \y) node[squarednode] {$X_{\nextstep{\x}}^{*}$};
        
    \foreach \y [count=\yi from 5] in {4.5,...,0.5}
    \foreach \x in {5.5,...,\yi+.5} 
        \draw (\x, \y) node[squarednode,dashed] {0};
        
    \end{tikzpicture}
\end{figure}

\end{document}

结果: 结果

或者使用该部分的强力变体%boxes

%boxes
    \draw (0.5, 5.5) node[squarednode] {$X_{1}^{*}$};
    \draw (1.5, 5.5) node[squarednode] {$X_{2}^{*}$};
    \draw (2.5, 5.5) node[squarednode] {$X_{3}^{*}$};
    \draw (3.5, 5.5) node[squarednode] {$X_{4}^{*}$};
    \draw (4.5, 5.5) node[squarednode] {$X_{5}^{*}$};
    
    \draw (1.5, 4.5) node[squarednode] {$X_{2}^{*}$};
    \draw (2.5, 4.5) node[squarednode] {$X_{3}^{*}$};
    \draw (3.5, 4.5) node[squarednode] {$X_{4}^{*}$};
    \draw (4.5, 4.5) node[squarednode] {$X_{5}^{*}$};
    \draw (5.5, 4.5) node[squarednode,dashed] {0};

    \draw (2.5, 3.5) node[squarednode] {$X_{3}^{*}$};
    \draw (3.5, 3.5) node[squarednode] {$X_{4}^{*}$};
    \draw (4.5, 3.5) node[squarednode] {$X_{5}^{*}$};
    \draw (5.5, 3.5) node[squarednode,dashed] {0};
    \draw (6.5, 3.5) node[squarednode,dashed] {0};
    
    \draw (3.5, 2.5) node[squarednode] {$X_{4}^{*}$};
    \draw (4.5, 2.5) node[squarednode] {$X_{5}^{*}$};
    \draw (5.5, 2.5) node[squarednode,dashed] {0};
    \draw (6.5, 2.5) node[squarednode,dashed] {0};
    \draw (7.5, 2.5) node[squarednode,dashed] {0};
    
    \draw (4.5, 1.5) node[squarednode] {$X_{5}^{*}$};
    \draw (5.5, 1.5) node[squarednode,dashed] {0};
    \draw (6.5, 1.5) node[squarednode,dashed] {0};
    \draw (7.5, 1.5) node[squarednode,dashed] {0};
    \draw (8.5, 1.5) node[squarednode,dashed] {0};
    
    \draw (5.5, 0.5) node[squarednode,dashed] {0};
    \draw (6.5, 0.5) node[squarednode,dashed] {0};
    \draw (7.5, 0.5) node[squarednode,dashed] {0};
    \draw (8.5, 0.5) node[squarednode,dashed] {0};
    \draw (9.5, 0.5) node[squarednode,dashed] {0};

答案2

哇,这太复古了!感觉就像 1985 年,当时的picture环境是你能得到的最佳图形(在 LaTeX 中)。

免责声明:我认为从长远来看,您不会对这个解决方案感到满意,因为它的维护会变得越来越麻烦。此外,通过定义一些宏可以避免很多重复。但是,我尝试尽可能少地进行修改,以便您仍然感到舒适。

在此处输入图片描述

\documentclass{article}
\usepackage{xcolor}
\usepackage{rotating}
\usepackage{pgffor}
\begin{document}

\setlength{\unitlength}{0.5in}

\begin{picture}(7.5,6.5)(-0.7,-1.2) % bounding box
  % vertical lines
  \multiput(1.75,4.8)(0.5,0){11}{\color{gray}\line(0,-1){6}}
  % labeling
  \foreach \x/\ss in {1.75/00,2.25/01,2.75/02,3.25/03,3.75/04,4.25/05,4.75/06,5.25/07,5.75/08,6.25/09,6.75/10}%
     {\put(\x,5.1){\makebox(0,0){\begin{sideways}\scriptsize11:\ss\end{sideways}}}}

  \put(-.25,4){\makebox(0.50,0.50){11:00-11:05}}
  \put(1.75,4){\framebox(0.5,0.5){$X_{1}^{*}$}}
  \put(2.25,4){\framebox(0.5,0.5){$X_{2}^{*}$}}
  \put(2.75,4){\framebox(0.5,0.5){$X_{3}^{*}$}}
  \put(3.25,4){\framebox(0.5,0.5){$X_{4}^{*}$}}
  \put(3.75,4){\framebox(0.5,0.5){$X_{5}^{*}$}}

  \put(-.25,3){\makebox(0.50,0.50){11:01-11:06}}        
  \put(2.25,3){\framebox(0.5,0.5){$X_{2}^{*}$}}
  \put(2.75,3){\framebox(0.5,0.5){$X_{3}^{*}$}}
  \put(3.25,3){\framebox(0.5,0.5){$X_{4}^{*}$}}
  \put(3.75,3){\framebox(0.5,0.5){$X_{5}^{*}$}}
  \put(4.25,3){\dashbox{0.05}(0.50,0.5){0}}

  \put(-.25,2){\makebox(0.50,0.50){11:02-11:07}}        
  \put(2.75,2){\framebox(0.5,0.5){$X_{3}^{*}$}}
  \put(3.25,2){\framebox(0.5,0.5){$X_{4}^{*}$}}
  \put(3.75,2){\framebox(0.5,0.5){$X_{5}^{*}$}}
  \put(4.25,2) {\dashbox{0.05}(0.50,0.5){0}}
  \put(4.75,2){\dashbox{0.05}(0.50,0.5){0}}

  \put(-.25,1){\makebox(0.50,0.50){11:03-11:08}}        
  \put(3.25,1){\framebox(0.5,0.5){$X_{4}^{*}$}}
  \put(3.75,1){\framebox(0.5,0.5){$X_{5}^{*}$}}
  \put(4.25,1) {\dashbox{0.05}(0.50,0.5){0}}
  \put(4.75,1) {\dashbox{0.05}(0.50,0.5){0}}
  \put(5.25,1){\dashbox{0.05}(0.50,0.5){0}}

  \put(-.25,0){\makebox(0.50,0.50){11:04-11:09}}        
  \put(3.75,0){\framebox(0.5,0.5){$X_{5}^{*}$}}
  \put(4.25,0){\dashbox{0.05}(0.50,0.5){0}}
  \put(4.75,0) {\dashbox{0.05}(0.50,0.5){0}}
  \put(5.25,0) {\dashbox{0.05}(0.50,0.5){0}}
  \put(5.75,0){\dashbox{0.05}(0.50,0.5){0}}

  \put(-.25,-1){\makebox(0.50,0.50){11:05-11:10}}        
  \put(4.25,-1) {\dashbox{0.05}(0.50,0.5){0}}
  \put(4.75,-1){\dashbox{0.05}(0.50,0.5){0}}
  \put(5.25,-1) {\dashbox{0.05}(0.50,0.5){0}}
  \put(5.75,-1) {\dashbox{0.05}(0.50,0.5){0}}
  \put(6.25,-1){\dashbox{0.05}(0.50,0.5){0}}
\end{picture}

\end{document}

相关内容