7

I'm trying to make a map of word correlations that will include a table of words with similar groupings marked by surrounding them with a rectangle with rounded corners. This needs to also be possible to do diagonals as in Example 2 below. Is this possible to do in latex?

Thanks a lot.

Example Table 2

Example Table

James
  • 565
  • 6
  • 13

2 Answers2

8

run with xelatex

\documentclass[]{article}
\usepackage{pst-node}
\begin{document}
\begin{psmatrix}[colsep=1cm, rowsep=1cm]
     A1& B1& C1& D1 \\
     A2& B2& C2& D2 \\
     A3& B3& C3& D3 \\
     A4& B4& C4& D4 
\end{psmatrix}  
\ncbox[linecolor=blue,nodesep=5pt,linearc=0.4]{2,1}{1,2} 
\ncarcbox*[linecolor=yellow,nodesep=5pt,linearc=0.4,arcangle=50,opacity=0.4]{2,2}{3,4} 
\ncbox[linecolor=red,nodesep=5pt,linearc=0.4]{2,3}{4,4}

\end{document}

enter image description here

if you need it with curves then look here: http://tug.org/PSTricks/main.cgi?file=Lines/lines#curves

Moriambar
  • 11,466
  • This works well, except that sometimes by cells have longer words in them, and the line cuts through the word. – James Oct 22 '13 at 05:57
  • that can be changed by the optional argument boxsize=... –  Oct 22 '13 at 06:01
7

This is one way to do, where matrix node is used

enter image description here

Code

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows}
\begin{document}
\begin{tikzpicture}%[thick]
  \matrix (mat) [%
    matrix of nodes, column sep=1cm, row sep=1cm
  ] 
  {%
     A1& B1& C1& D1 \\
     A2& B2& C2& D2 \\
     A3& B3& C3& D3 \\
     A4& B4& C4& D4 \\
  };  
  \draw[blue,very thick, rounded corners] (mat-2-1.north west) --(mat-1-2.north west) -| (mat-1-2.south east)-- (mat-2-1.south east) -| (mat-2-1.north west); 

 \draw[yellow,very thick] (mat-2-2.north west) -| (mat-2-2.south east) -- (mat-3-2.south east) -- (mat-3-2.south west) --(mat-2-2.north west); 

 \draw[green,very thick] (mat-1-3.north west) -| (mat-1-3.south east) -- (mat-2-3.south east) -- ++(0,-0.5cm) -| (mat-1-3.north west); 

 \draw[red,very thick] (mat-2-3.north west) -| (mat-2-4.north east) -- (mat-2-4.south east) -- (mat-2-3.south west)-- ++(-0.5cm,0) |-(mat-2-3.north west); 
\end{tikzpicture}
\end{document}
Jesse
  • 29,686
  • Thanks! Can this be done with rounded corners? – James Oct 22 '13 at 05:22
  • Also, is there a way to set it so the lines have different 'radii' from the cell centre? So that around C2 you'd be able to see both the red and green lines? – James Oct 22 '13 at 05:24
  • @Venning -- Yes, just add options 'rounded corner' into the draw options, same location as very thick and color. For the second concern, I will say add a relative distance -- ++(0,-1cm) to the draw. – Jesse Oct 22 '13 at 05:30
  • @Venning -- Please see my update and a relative distance is added on the green one. – Jesse Oct 22 '13 at 05:36
  • That's really great. – James Oct 22 '13 at 05:53
  • If the cells have varying width, is there any way to cause the border to go around the whole cell, rather than the text itself? – James Oct 22 '13 at 05:53
  • @Venning -- My understanding of this matrix node is that the anchor things (north east, north west, ...) are associated to the four corners of a cell/grid. As long as the contents are located inside of cells, the border will go around the whole cell. – Jesse Oct 22 '13 at 06:07