2

I would like to add in my tikz picture a parenthesis like this :

parenthesis to add

I have already tried adding a \[\left( before and a \right)\] around the tikzpicture.

But it doesn't give the desired result:

enter image description here

Here's my code :

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{patterns}
\usetikzlibrary{decorations.pathreplacing,angles,quotes}


% defining the new dimensions and parameters
\newlength{\hatchspread}
\newlength{\hatchthickness}
\newlength{\hatchshift}
\newcommand{\hatchcolor}{}
% declaring the keys in tikz
\tikzset{hatchspread/.code={\setlength{\hatchspread}{#1}},
         hatchthickness/.code={\setlength{\hatchthickness}{#1}},
         hatchshift/.code={\setlength{\hatchshift}{#1}},% must be >= 0
         hatchcolor/.code={\renewcommand{\hatchcolor}{#1}}}
% setting the default values
\tikzset{hatchspread=10pt,
         hatchthickness=0.4pt,
         hatchshift=0pt,% must be >= 0
         hatchcolor=black}
% declaring the pattern
\pgfdeclarepatternformonly[\hatchspread,\hatchthickness,\hatchshift,\hatchcolor]% variables
   {custom north west lines}% name
   {\pgfqpoint{\dimexpr-2\hatchthickness}{\dimexpr-2\hatchthickness}}% lower left corner
   {\pgfqpoint{\dimexpr\hatchspread+2\hatchthickness}{\dimexpr\hatchspread+2\hatchthickness}}% upper right corner
   {\pgfqpoint{\dimexpr\hatchspread}{\dimexpr\hatchspread}}% tile size
   {% shape description
    \pgfsetlinewidth{\hatchthickness}
    \pgfpathmoveto{\pgfqpoint{0pt}{\dimexpr\hatchspread+\hatchshift}}
    \pgfpathlineto{\pgfqpoint{\dimexpr\hatchspread+0.15pt+\hatchshift}{-0.15pt}}
    \ifdim \hatchshift > 0pt
      \pgfpathmoveto{\pgfqpoint{0pt}{\hatchshift}}
      \pgfpathlineto{\pgfqpoint{\dimexpr0.15pt+\hatchshift}{-0.15pt}}
    \fi
    \pgfsetstrokecolor{\hatchcolor}
%    \pgfsetdash{{1pt}{1pt}}{0pt}% dashing cannot work correctly in all situation this way
    \pgfusepath{stroke}
   }

\begin{document}

\begin{center}
\begin{tikzpicture}
\draw [fill=orange!50,draw=black](0,7) rectangle (0.2,10);
\draw[pattern=custom north west lines] (0,6) rectangle (0.2,7);
\draw [fill=orange!50,draw=black](0,0) rectangle (0.2,6);

\draw [fill=orange!50,draw=black](2,7) rectangle (2.2,10);
\draw[pattern=custom north west lines] (2,6) rectangle (2.2,7);
\draw [fill=orange!50,draw=black](2,0) rectangle (2.2,6);

\draw [fill=orange!50,draw=black](4,7) rectangle (4.2,10);
\draw[pattern=custom north west lines] (4,6) rectangle (4.2,7);
\draw [fill=orange!50,draw=black](4,0) rectangle (4.2,6);
\end{tikzpicture}

\end{center}

\end{document}

Does anyone have an idea? Thank you in advance !

1
2

Define a suitable baseline of the picture. The parentheses \left(...\right) extend as far below the baseline as the object is high. Use e.g.

 \begin{tikzpicture}[baseline={(0,4.9)}]

For a pure tikz solution, see "draw round/rectangular bracket embracing nodes in tikz".

enter image description here

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{patterns}
\usetikzlibrary{decorations.pathreplacing,angles,quotes}


% defining the new dimensions and parameters
\newlength{\hatchspread}
\newlength{\hatchthickness}
\newlength{\hatchshift}
\newcommand{\hatchcolor}{}
% declaring the keys in tikz
\tikzset{hatchspread/.code={\setlength{\hatchspread}{#1}},
         hatchthickness/.code={\setlength{\hatchthickness}{#1}},
         hatchshift/.code={\setlength{\hatchshift}{#1}},% must be >= 0
         hatchcolor/.code={\renewcommand{\hatchcolor}{#1}}}
% setting the default values
\tikzset{hatchspread=10pt,
         hatchthickness=0.4pt,
         hatchshift=0pt,% must be >= 0
         hatchcolor=black}
% declaring the pattern
\pgfdeclarepatternformonly[\hatchspread,\hatchthickness,\hatchshift,\hatchcolor]% variables
   {custom north west lines}% name
   {\pgfqpoint{\dimexpr-2\hatchthickness}{\dimexpr-2\hatchthickness}}% lower left corner
   {\pgfqpoint{\dimexpr\hatchspread+2\hatchthickness}{\dimexpr\hatchspread+2\hatchthickness}}% upper right corner
   {\pgfqpoint{\dimexpr\hatchspread}{\dimexpr\hatchspread}}% tile size
   {% shape description
    \pgfsetlinewidth{\hatchthickness}
    \pgfpathmoveto{\pgfqpoint{0pt}{\dimexpr\hatchspread+\hatchshift}}
    \pgfpathlineto{\pgfqpoint{\dimexpr\hatchspread+0.15pt+\hatchshift}{-0.15pt}}
    \ifdim \hatchshift > 0pt
      \pgfpathmoveto{\pgfqpoint{0pt}{\hatchshift}}
      \pgfpathlineto{\pgfqpoint{\dimexpr0.15pt+\hatchshift}{-0.15pt}}
    \fi
    \pgfsetstrokecolor{\hatchcolor}
%    \pgfsetdash{{1pt}{1pt}}{0pt}% dashing cannot work correctly in all situation this way
    \pgfusepath{stroke}
   }

\begin{document}

\begin{center}
$\left(\quad\begin{tikzpicture}[baseline={(0,4.9)}]
\draw [fill=orange!50,draw=black](0,7) rectangle (0.2,10);
\draw[pattern=custom north west lines] (0,6) rectangle (0.2,7);
\draw [fill=orange!50,draw=black](0,0) rectangle (0.2,6);

\draw [fill=orange!50,draw=black](2,7) rectangle (2.2,10);
\draw[pattern=custom north west lines] (2,6) rectangle (2.2,7);
\draw [fill=orange!50,draw=black](2,0) rectangle (2.2,6);

\draw [fill=orange!50,draw=black](4,7) rectangle (4.2,10);
\draw[pattern=custom north west lines] (4,6) rectangle (4.2,7);
\draw [fill=orange!50,draw=black](4,0) rectangle (4.2,6);
\end{tikzpicture}\quad\right)$

\end{center}

\end{document}
1
  • Thank you for you answer ! This is what I was looking for! – RedWest Feb 13 at 21:57

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.