Quantcast
Channel: Draw a line that encloses some objects in TikZ - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 2

Answer by Schrödinger's cat for Draw a line that encloses some objects in TikZ

$
0
0

Here is one possible way, very much as @cfr suggests but with a local bounding box instead of fit.

\documentclass[border=4pt]{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  [every node/.style={draw=LimeGreen, fill=LimeGreen!15,
    circle, inner sep=.1111em, minimum size=1.2222em},
   thick]
  \begin{scope}[local bounding box=circs]
  \node [] (01) at (0,0) {1};
  \node [left] (02) at (01.west) {};
  \node [left] (03) at (02.west) {};
  \node [left] (04) at (03.west) {};

  \node [above] (05) at (01.north) {};
  \node [above] (06) at (02.north) {};
  \node [above] (07) at (03.north) {3};
  \node [above] (08) at (04.north) {};

  \node [below] (09) at (01.south) {};
  \node [below] (10) at (02.south) {};
  \node [below] (11) at (03.south) {};
  \node [below] (12) at (04.south) {};
  \end{scope}
  \draw[rounded corners={(1.2222em+2*\pgflinewidth)/2}] ([xshift=-\pgflinewidth]circs.north west) 
  |- ([yshift=-\pgflinewidth]circs.south) -| ([xshift=\pgflinewidth]circs.north east);
\end{tikzpicture}
\end{document}

enter image description here

Off-topic: you'd be way better off with a matrix of nodes IMHO.

\documentclass[border=4pt]{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[thick]
  \matrix[matrix of nodes,nodes in empty cells,inner sep=0pt,outer
  sep=\pgflinewidth/2,
  cells={nodes={draw=LimeGreen, fill=LimeGreen!15,execute at begin
  node=\vphantom{1},
    circle, inner sep=.1111em, minimum size=1.2222em}}] (circs)
    { & 3 & & \\
      &   & & 1 \\
      & & & \\};
  \draw[rounded corners={(1.2222em+2*\pgflinewidth)/2}] (circs.north west) 
  |- (circs.south) -| (circs.north east);
\end{tikzpicture}
\end{document}

enter image description here


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>