2

Hi: I'm a latex novice but I managed to make the picture below. The thing that I don't know how to do is make it clear that the first box runs from 11:00 -11:01, the second box runs from 11:01-11:02, the third box runs from 11:02-11:03, ... and the tenth box runs from 11:09-11:10. Basically, I want to make it clear that the boxes are actually on a horizontal axis that spans the period 11:00-11:10. If I went about this in a way that doesn't make this possible or too easy, I'm willing to change to some totally different method but I'm even more of a novice at making latex pictures so I don't know what that is. At first I was trying to use tikz but I found it more complicated than I needed but maybe I was wrong. Thanks a lot for any help.

\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}

Result: result

  • Welcome to TeX.SX! If I understand you correctly, then your question is not really about LaTeX, but rather about the best way to visualize whatever you want to express. If yes, then this is the wrong place to ask, at least unless you give a lot more background. Otherwise, if the question is about how to typeset a drawing you have in mind, make a drawing by hand and upload the picture. – gernot says Reinstate Monica Nov 8 at 22:35
  • 2
    Michael Chatiskatzi was kind enough to make my latex code into an actual image. Thanks Michael. I want to have tick marks along the x-axis with labels under the tick marks denoting the time. So, the 11:00 - 11:05 line should have 11:00 under the left side of the first box, 11:01 under the right side of the first box ( which is the same as the left side of the second box ), 11:02 on the right side of the second box etc. So. basically how to label the axis to be consistent with what it says on the left. Thanks for any tips. Also, if it's still better for me to upload an image, I can do that. – mark leeds Nov 8 at 23:38
1

If somebody is interested in the TikZ version, he can find it here.

\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\relax -\fi#1} % create new command \absval to get the absolut value of the argument
    \newcommand{\fullmin}[1]{\ifnum\absval{#1}<10\relax 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}

Result: result

Or with the brute force variant for the %boxes section:

%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};
  • wow michael. this is also quite amazing and the code looks easier. thanks. I'm still working on understanding the other one. I have so many latex books but is there one particular one that anyone recommends that would sort of go through what this answer or the other answer did. I'm on some other lists but this one is making me realize that I'm more novicey than I even knew. I think there's a saying for that to the tune of "they know so little that they don't even know what they don't know". – mark leeds Nov 9 at 2:57
  • I checked the one that came later because I prefer the horizontal axis be on the bottom rather than the top. They're both great. I'm confident that, over time, I'll learn a lot from them. thank you michael and gernot. – mark leeds Nov 9 at 3:24
  • Michael: When I make a tex file out of your code and try to do pdflatex on it, I get the error below. Do you know how I can fix that ? ! Illegal unit of measure (pt inserted). <to be read again> +l.35 ...de[squarednode] {$X_{\nextstep{\x}}^{*}$}; \yi l.35 ...de[squarednode] {$X_{\nextstep{\x}}^{*}$}; ? – mark leeds Nov 9 at 3:52
  • First of all, thank you for accepting the answer. I will try to comment on the code during the day and keep it as understandable as possible. I'm also just an advanced beginner, I would say. It may well be that this version can be written much easier and more nicely than that. – Michael Chatiskatzi Nov 9 at 9:52
  • To go into the error now: Did you copy the code exactly like that? Because according to the message it looks like \draw (\x, \y) node[squarednode] {$X_{\nextstep{\x}}^{*}$}; is followed by \yi in the next line. – Michael Chatiskatzi Nov 9 at 9:57
3

Wow, this was retro! Felt like 1985, when the picture environment was the best graphics you could get (in LaTeX).

Disclaimer: I don't think that in the long run you will be happy with this solution, since it will get more and more cumbersome to maintain. Moreover, there is a lot of duplication that one could avoid by defining some macros. However, I tried to modify as little as possible such that you still feel at home.

enter image description here

\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}
  • OMG. This is amazing. I have to try to understand it but it's so appreciated. – mark leeds Nov 8 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.