I asked a question here but, rather stupidly, added extra information after it had been answered.
My additional question is this:
I have a table with varying lengths of words. I want to encircle different groups of cells, including diagonals. If possible, it would be great if the rectangles don't overlap each other where possible.
I looked at the answer here, which, whilst tedious, worked except for the overlap.
This is where I've got to so far:
\documentclass[fleqn,12pt,a4paper,landscape]{article}
\usepackage{tikz}
\usepackage{tabularx}
\begin{document}
% Introduce a new counter for counting the nodes needed for circling
\newcounter{nodecount}
% Command for making a new node and naming it according to the nodecount counter
\newcommand\tabnode[1]{\addtocounter{nodecount}{1} \tikz \node (\arabic{nodecount}) {#1};}
% Some options common to all the nodes and paths
\tikzstyle{every picture}+=[remember picture,baseline]
\tikzstyle{every node}+=[inner sep=0pt,anchor=base,
minimum width=1.8cm,align=center,text depth=.25ex,outer sep=1.5pt]
\tikzstyle{every path}+=[thick, rounded corners]
\begin{table}[ht]
\begin{minipage}[b]{1 \linewidth}\centering
\begin{tabular}{cccccc}
% Turn the cells needed for defining the circling paths into nodes with our custom command
\tabnode{Long ago}& \tabnode{A few days ago}& \tabnode{Day before yesterday}& \tabnode{Yesterday} & & \\
& & & & \tabnode{Today} & \tabnode{Now}\\
\tabnode{Long time in the future}& \tabnode{A few days on}& \tabnode{Day after tomorrow}& \tabnode{Tomorrow} & & \\
\end{tabular}
\end{minipage}
\begin{tikzpicture}[overlay]
% Define the circle paths
\draw [blue](1.north west) -- (1.north east) -| (7.north east) |- (7.south west) |- (1.north west);
\draw [red](8.south west) -| (2.north east) -| (2.south west) |- (8.south west);
\draw [yellow](9.south west) -| (3.north east) -| (3.south west) |- (9.south west);
\draw [green](8.south west) -| (3.north east) -| (2.south west) |- (8.south west);
\end{tikzpicture}
\end{table}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
Best Answer
That is easy with
fit
library.Adjust the
node sep
to suit your needs. There is alsoouter sep
with which you can play around.Full image will be:
You code with
fit
library will be: