TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to draw the following diagram in LaTeX.

The image is:

enter image description here

I was looking at the TikZ package and it seems to be what I need. However, I need to automate somehow the task of drawing this diagram, because I need to draw hundreds of them. I was wondering if it is possible to create a LaTeX command, probably based on TikZ, doing something like:

\QOC{{How wide?}, {Narrow, Wide}, {Screen compactness, Ease of hiting with a mouse}, 2, {1}, {2}}

which corresponds to the first diagram of the figure. The first group contains the questions, the second one the options, the third one criteria, the first number (2) is the selected option, the group of numbers {1} indicates the positive assessments for option 1 (i.e., it has a positive assessment to the criterion number ONE) and the second group of numbers contains the positive assessments for the second option, which in this case is 2, i.e., the second criteria.

For the question How to display?, the command would be:

\QOC{{How to display?}, {Permanent, Appearing}, {Low user effort, Screen compactness, Continuous feedback to user}, 2, {1,3}, {2}}
share|improve this question
Thank you for editing Claudio. – DConversor May 3 '12 at 14:49
Hi DConversor, welcome to TeX.sx! We've edited the question a bit. You can format code by selecting it and pressing the {} button, or enclosing it in backticks (for inline code) or indenting by four spaces (for code blocks). I've also removed the "Thanks" from the message, that's just the common style here. – Jake May 3 '12 at 14:51
Do you need it once or twice or do you need to use it plenty of times? In the former case, it can be drawn e.g. in TikZ. In the latter case, it would be worth making a powerful weapon, i.e. a LaTeX package... (However, I don't say I would be able to do such package). – yo' May 3 '12 at 15:07
Thank you for the interest tohecz. I need to draw more than one hundred of diagrams. Regardless of the automation process, are you able to draw just one with tikz? Thank you again. – DConversor May 3 '12 at 15:15
@DConversor: do you have every time in the second stage two items or they could be more than that? – Claudio Fiandrino May 4 '12 at 12:48

Here you have the first one. It uses trees library. You will find information about TiKZ's trees in chapters "Tutorial: A Lecture Map for Johannes", "Making Trees Grow" and "Tree Library" from TiKZ manual. Please read them (and some other Tutorial chapters) to understand following code. This is just an example, every node, edge, text could be changed.

Another option would be Tikz-qtree. You can also search for tree here and will obtain more than 400 questions with answers.



    growth parent anchor=east,
    parent anchor=east,
    child anchor=west,
    level distance=2cm,
    every node/.style={anchor=east,text width=2.5cm, align=left},
    every child node/.style={anchor=west},
    level 1/.style={nodes={text width=\widthof{O: Narrow}}}]

\node (Q1) {Q: How wide?}   
   child {node [draw] (O2) {O: Wide}
        child {node[text width=3cm] (C2) {C: Ease of heating\\with the mouse}}}
    child {node (O1) {O: Narrow}
        child {node (C1) {C: Screen\\ compactness}}
\draw[dashed] (O1.east)--(C2.west) (O2.east)--(C1.west);

enter image description here

share|improve this answer
Although presumably a typo, the ease of "heating with a mouse" is one of the most charming benefits imaginable from a wide widget. Green energy indeed. – Paul Stanley May 4 '12 at 9:22
@PaulStanley: Of course was a typo! Being spanish, hitting and heating sound the same to me. But I don't know if "hitting with a mouse" is better than "heating with a mouse". – Ignasi May 4 '12 at 10:02
Worse, for the mouse, I suppose! – Paul Stanley May 4 '12 at 11:12
This is wonderful! Thank you for the code and for the references. I will take a look to them for sure. Also the diagram looks very nice. Now the question is, is there a way to automate this? Maybe with a macro, but I never write one. Thank you again for the detailed answer. PD: Of course it was a typo :) – DConversor May 4 '12 at 12:05

I provide a solution, based on TikZ, that automates the process of creation by simply calling this command:

\qoc{How wide?}{Wide,Narrow}{1}{Ease of hitting with a mouse,Screen compactness}{{1},{2}}{{2},{1}}

It is quite heavy in the number of arguments unfortunately; let's examine them:

  • the first one is the starting point;
  • the second contains the list of items in the second stage (the first one is shown in the bottom);
  • the third command allows you to decide which of the items in the second stage is selected and thus put into a box;
  • the fourth contains the list of items in the third stage (with the same rule: the first is put in the bottom, the last on the top)
  • the fifth command is used to create positive edges (with a countinuous line); the rule is the following: {{1},{2}} means that the first module of the second stage is connected with the first module of the third stage; you can list them, thus {{2},{1,3}} means that the second module of the second stage is connected with the first and third module of the third stage;
  • the sixth command is quite similar to the previous one, but it is used to create negative edges (with a dashed line).

I know that it seems quite strange, but look at the MWE:


\begin{tikzpicture}[every node/.style={anchor=center, align=left},
thirdstage/.style={anchor=west,text width=4cm, align=left},rotate=-90]  

% First stage
\node (X){Q: #1};

\foreach \z [count=\xi] in {#2}  {\global\let\maxz\xi}  
\foreach \w [count=\yi] in {#4}  {\global\let\maxw\yi}  

% Nodes definition second stage
\foreach \z [count=\xi] in {#2}
\node[rectangle,draw] (X\xi) at (\angle:2.5cm) {O: \z };
\node (X\xi) at (\angle:2.5cm) {O: \z };
\path (X)edge(X\xi) ;

% Nodes definition third stage
\foreach \w [count=\yi] in {#4}
\node[thirdstage,xshift=5cm] (XX\yi) at (\angle:2.5cm) {C: \w};

% Positive connections   (dashed)
\foreach \x [count=\xi] in {#5}
\foreach \y  in \x

% Negative connections (dashed)
\foreach \x [count=\xi] in {#6}
\foreach \y  in \x


\qoc{How wide?}{Wide,Narrow}{1}{ Ease of hitting with a mouse,Screen compactness}{{1},{2}}{{2},{1}}


\qoc{How to display?}{Appearing,Permanent}{1}{Continuous feedback to users,Screen compactness,Low user effort}{{2},{3,1}}{{1,3},{2}}

\qoc{How to display?}{Appearing,Permanent}{1}{Continuous feedback to users,Screen compactness,Low user effort,No user effort}{{2,4},{3,1}}{{1,3},{2,4}}

that gives you:

enter image description here

The part you really have to insert inside the document is not too much distant from the pseudo code you provided in the question; moreover my solution guarantees you that it works for a variable number of items (not too large I think) in both stages.

share|improve this answer
OMG This seems to be exactly what I need! Thank you so much Claudio!! I will test it as soon as possible. Best regards, DConversor – DConversor May 4 '12 at 15:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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