4

I want to put brace and its mirror at left and right side of a rectangle with some horizontal gap between rectangle and braces. I used following code but it puts gap only at north side and not the south side. How to put a horizontal gap between brace and rectangle at both north and south sides.

\documentclass[12pt]{article}
\usepackage{lingmacros}
\usepackage{tree-dvips}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart,shapes,shadows,arrows.meta,arrows,decorations.markings,trees,positioning,decorations.markings,calc,fit,chains,intersections,decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
\node[draw,text depth = 6cm, minimum width=7cm] (auth) {};
\node[draw,text depth = 3cm, minimum width=6cm] at ([yshift=-3cm]auth.north) (gen) {};
\draw [decorate, decoration={brace,amplitude=5pt}] (gen.north east)+(0.5cm, 0cm) -- (gen.south east)+(0.5cm, 0cm);
\draw [decorate, decoration={brace,amplitude=5pt,mirror}] (gen.north west)+(-0.5cm,0cm) -- (gen.south west)+(-0.5cm, 0cm);
\end{tikzpicture}
\end{document}
4

I don't think that manual adjustment like (gen.north east)+(0.5cm, 0cm) is a goof thing here. I think that it's better to use (gen.north -| auth.east) which takes the y-coordinate from gen.north and the x-coordinate from auth.east. Then you can use raise parameter to adjust the position of the braces.

\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
  \begin{tikzpicture}
    \path
      node[draw,minimum height = 6cm, minimum width=7cm] (auth) {}
      node[draw,minimum height = 3cm, minimum width=6cm] (gen) {};
    \begin{scope}[red, decoration={brace,amplitude=5pt,raise=3pt}]
      \draw[decorate] (gen.north -| auth.east) -- (gen.south -| auth.east);
      \draw[decorate, decoration={mirror}] (gen.north -| auth.west) -- (gen.south -| auth.west);
    \end{scope}
  \end{tikzpicture}
\end{document}

enter image description here

I have also corrected in your code:

  • all useless libraries (you have included decorations.markings two times!),
  • the manual adjustments for the position of the (gen) node,
  • replaced text depth by minimum height,
  • introduced a scope for all common decorations.
|improve this answer|||||
3

It doesn't work because (a) +(5mm,0) -- (b) +(5mm,0) means

  1. place pen at a
  2. move pen to the point 5mm right of a
  3. draw line to b
  4. move pen to point 5mm right of b

You have many options though.

  • the syntax of the calc library, e.g. ($(gen.north east)+(0.5cm, 0cm)$)
  • the raise keyword
  • shift/xshift/yshift in the last coordinate, as percusse mentioned in his (now deleted) answer, e.g. (gen.south east)+(0,-0.5cm) -- ([shift={(0,-0.5cm)}]gen.south west).
  • if your purpose is to have the braces along the edge of the outer rectangle, you can use perpendicular coordinates, as demonstrated below

enter image description here

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc}
\begin{document}
\begin{tikzpicture}
\node[draw,text depth = 6cm, minimum width=7cm] (auth) {};
\node[draw,text depth = 3cm, minimum width=6cm] at ([yshift=-3cm]auth.north) (gen) {};

% calc library
\draw [decorate, decoration={brace,amplitude=5pt}] 
        ($(gen.north east)+(0.8cm, 0cm)$) -- ($(gen.south east)+(0.8cm, 0cm)$);

% raise key
\draw [decorate,
       decoration={
          brace,
          amplitude=5pt,
          mirror,
          raise=8mm} % <--- raise key to move brace away
       ] (gen.north west) -- (gen.south west);


% shift one coordinate
\draw [decorate, decoration={brace,amplitude=5pt}] (gen.south east)+(0,-0.5cm) -- ([shift={(0,-0.5cm)}]gen.south west);


% if the brace should be along the outer rectangle
% perpendicular coordinates
\draw [decorate, decoration={brace,amplitude=5pt}]
     (gen.north east-|auth.east) -- (gen.south east-|auth.east);

\draw [decorate, decoration={brace,amplitude=5pt,mirror}]
     (gen.north west-|auth.west) -- (gen.south west-|auth.west);

\end{tikzpicture}
\end{document}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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