10

I'm trying to reproduce the diagram below using xymatrix package: enter image description here

This is what I've done so far:

\documentclass{article}

\usepackage[all]{xy}

\begin{document}

\xymatrix@C=1cm{
    % First row
    \txt{FASE I\\Planejamento da Revisão} & 
    \txt{FASE II\\Realização da Revisão} &
    \txt{FASE III\\Documentação da Revisão} &
    \\
    % Second row
    *++[F-,]\txt{1. Especificar questões da\\ pesquisa} \ar[d] & 
    *++[F-,]\txt{3. Identificar e selecionar\\ pesquisas} \ar[d] & 
    *++[F-,]\txt{7. Analisar resultados} \ar[d]
    \\
    % Third row
    *++[F-,]\txt{2. Desenvolver protocolo da\\ revisão questões da pesquisa} \ar[ur] &
    *++[F-,]\txt{4. Avaliar a qualidade dos\\ estudos} \ar[d] &
    *++[F-,]\txt{8. Elaborar relatório}
    \\
    % Fourth row
    & *++[F-,]\txt{5. Extrair dados} \ar[d] & 
    \\
    % Fifth row
    & *++[F-,]\txt{6. Sintetizar dados} \ar[uuur] & 
    \\
}

\end{document}

Which gives me this: enter image description here

How can I reproduce using xymatrix package the arrow between step 2 and 3 and between step 6 and 7, so it turns and doesn't pass through the other steps?

Also, how can I "group" each column in a frame, as it is in the original diagram?

4
  • 2
    Welcome! Please provide the complete code, i.e. an MWE that starts with \documentclass` and ends with \end{document}. And you might want to specify if you're open to solutions based on other packages like, say, TikZ.
    – user121799
    Commented Feb 11, 2018 at 20:35
  • Thank you for the tip! I've added the MWE and I'm not interested in solutions based in packages otherwise than xymatrix, I'll update that on the question.
    – lucascb
    Commented Feb 11, 2018 at 20:51
  • 1
    tex.stackexchange.com/a/316755/107497 has an approach that involves using the backtick character to make your arrows turn and adding phantom columns so that you can turn between the actual columns.
    – Teepeemm
    Commented Feb 11, 2018 at 21:55
  • I've used the backtick character, but couldn't make it work. I'll take a look on this phantom columns trick. Thank you!
    – lucascb
    Commented Feb 12, 2018 at 0:20

2 Answers 2

11

I know you said that you only want xymatrix solutions, but I'm a tikz partisan and I only noticed you said that after I made this.

\documentclass{article}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{calc}
\usetikzlibrary{fit}

\begin{document}

\begin{tikzpicture}
\matrix (m) [
    matrix of nodes,
    row sep=0.4cm,
    column sep=1cm,
    % Set the size of the text boxes to be 4cm x 15pt
    every node/.style={text width=4cm, text depth=15pt},
    every node/.append code={ 
       % Check whether we're on the top row
       \ifnum\pgfmatrixcurrentrow=1\relax
          % Top row: align  center and don't draw rectangles
          \pgfkeysalso{align=center}
       \else
          % other rows: align left and "draw" the rectangles
          \pgfkeysalso{align=left,draw}
       \fi
    }
]{
% First row
% Need braces in order to use \\ as an explicit linebreak
{FASE I \\ Planejamento da Revisão} &
{FASE II\\ Realização da Revisão} &
{FASE III\\ Documentação da Revisão} \\
% Second row
1. Especificar questões da pesquisa &
3. Identificar e selecionar pesquisas &
7. Analisar resultados\\
% Third row
2. Desenvolver protocolo da revisãoa&
4. Avaliar a qualidade dos estudos&
8. Elaborar relatório\\
% Fourth row
& {5. Extrair dados}  &
\\
% Fifth row
% I need to force tikz to create empty nodes for fitting later
% But we don't want it to make empty rectangles, hence |[draw=none]|
|[draw=none]|& {6. Sintetizar dados} & |[draw=none]| 
\\};

\draw[->] (m-2-1) -- (m-3-1);
% Make the first zigzag path
\draw[->] (m-3-1.south)  -- ++(0,-0.5)
                   -| ($(m-2-2.west) - (0.5,0)$)
                   -- (m-2-2.west);
\draw[->] (m-2-2) -- (m-3-2);
\draw[->] (m-3-2) -- (m-4-2);
\draw[->] (m-4-2) -- (m-5-2);

% Make the second zigzag path
\draw[->] (m-5-2.east)  -- ++(0.5,0)
                   |- (m-2-3.west);

\draw[->] (m-2-3) -- (m-3-3);

% Draw the three "fit" rectangles
\node[rectangle,draw,fit=(m-1-1)(m-5-1)]{}; 
\node[rectangle,draw,fit=(m-1-2)(m-5-2)]{};
\node[rectangle,draw,fit=(m-1-3)(m-5-3)]{};

\end{tikzpicture}
\end{document}  

enter image description here

2
  • Yeah I've tried to draw it using TikZ before, but I've found the syntax too complex. Then I moved to xymatrix, which I could get at least something close to what I expected. But thank you anyway, I'll study your source code so I can try on my other diagrams later.
    – lucascb
    Commented Feb 11, 2018 at 21:48
  • Yeah TikZ is pretty intimidating for new users. I added some comments which hopefully will make it a tiny bit easier to follow. Commented Feb 11, 2018 at 21:56
8

The best I've been able to get using backticks is

\documentclass{article}

\usepackage[all]{xy}

\begin{document}

\xymatrix{
    % First row
    \txt{FASE I\\Planejamento da Revisão}
    \ar[d]
     & &
    \txt{FASE II\\Realização da Revisão} & &
    \txt{FASE III\\Documentação da Revisão} & &
    \\
    % Second row
    *++[F-,]\txt{1. Especificar questões da\\ pesquisa} \ar[d] & &
    *++[F-,]\txt{3. Identificar e selecionar\\ pesquisas} \ar[d] & &
    *++[F-,]\txt{7. Analisar resultados} \ar[d]
    \\
    % Third row
    *++[F-,]\txt{2. Desenvolver protocolo da\\ revisão questões da pesquisa}
    \ar`d[dr]`[ur]`[urr][urr] % \ar[ur]
     & &
    *++[F-,]\txt{4. Avaliar a qualidade dos\\ estudos} \ar[d] & &
    *++[F-,]\txt{8. Elaborar relatório}
    \\
    % Fourth row
    & & *++[F-,]\txt{5. Extrair dados} \ar[d] & &
    \\
    % Fifth row
    & & *++[F-,]\txt{6. Sintetizar dados}
    \ar`r[ruuu]`[rruuu][rruuu] % \ar[uuur]
    & &
}

\end{document}

enter image description here

I tried to get the frames by adding headless arrows (\ar@{-}) offset from the appropriate matrix entries, but I couldn't figure out the offset syntax. I suppose you could use the "introduce extra columns" trick to have the frame corners at matrix entries, but now you're adding two rows and six columns to the matrix, which starts seeming excessive.

2
  • Yeah seems like tikz is really the right tool for the job. +1 for trying to do it the way he asked. Commented Feb 12, 2018 at 2:42
  • This is exactly what I was expecting to the arrows, appreciate your help! About the frames I tried by grouping objects using \save and \restore from section 3.6 of the xyguide, but the syntax is either complex and I couldn't figure out how to put it on practise.
    – lucascb
    Commented Feb 12, 2018 at 14:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .