0

I want to insert a TikZ picture into a TikZ graphic, is it possible?

Basically there is a box for every chapter header and I want to add a logo inside this box.

The TikZ code is a little weird but does it produce the desired result?

\documentclass[a4paper,11pt,fleqn]{book}
\usepackage{fontspec}  % If i disable this and every thing else labled with [A]
\usepackage[T1]{fontenc}% [A]
\usepackage[utf8]{inputenc}   
\usepackage{xcolor}
\usepackage{color}
\definecolor{mydarkgray}{RGB}{0,100,100}
\newcommand{\mytemplatecolor}{mydarkgray}

\usepackage{tikz}
\usepackage[explicit]{titlesec}
\newcommand*\chapterlabel{}
\titleformat{\chapter}[display]  % type (section,chapter,etc...) to vary,  shape (eg display-type)
%{\normalfont\bfseries\Huge} % and enable this ander very the other line   labled with [B] 
{\Huge\bfseries\sffamily\color{\mytemplatecolor}\fontspec[]{MetaBoldLF-Roman}} % [A]
{\gdef\chapterlabel{\thechapter\ }}     % the label 
{0pt} % separation between label and chapter-title
{\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-8cm,xshift=0cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
    \draw[fill=\mytemplatecolor,\mytemplatecolor] (0,0) rectangle(35.5mm,15mm);% Neu um es grau zu machen
    \node[anchor=north east,yshift=-7.2cm,xshift=34mm,minimum height=30mm,inner sep=0mm] at (current page.north west)
    {\parbox[top][30mm][t]{15mm}{\raggedleft $\phantom{\textrm{l}}$\color{white}\chapterlabel}};  %the black l is just to get better base-line alingement
    \node[anchor=north west,yshift=-7.2cm,xshift=37mm,text width=\textwidth,minimum height=30mm,inner sep=0mm] at (current page.north west)
    {\parbox[top][30mm][t]{\textwidth}{\color{\mytemplatecolor}#1}};
    \end{tikzpicture}
};
\end{tikzpicture}
\gdef\chapterlabel{}
} % code before the title body
\titlespacing*{\chapter}{-98pt}{38pt}{30pt} % [A]
%\titlespacing*{\chapter}{0pt}{50pt}{30pt} %[B]  than i do not need any offse here?
\begin{document}
\chapter{A Chapter} 
Tickz created this rectangle for my chapter headers.....


now i want to include this Logo:\\

{\begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1.000000, xscale=1.000000, inner sep=0pt, outer sep=0pt]
\path[draw=black,fill=black,line join=miter,line cap=round,miter
limit=4.00,nonzero rule,dash phase=3.000pt,line width=0.000pt]
(178.4915,651.0411) .. controls (178.0358,651.0411) and (177.5801,651.0411) ..
(177.1244,651.0411) .. controls (177.1244,652.6787) and (177.1244,654.3163) ..
(177.1244,655.9539) .. controls (177.5801,655.9539) and (178.0358,655.9539) ..
(178.4915,655.9539) .. controls (178.4915,654.3163) and (178.4915,652.6787) ..
(178.4915,651.0411) -- cycle;
\path[xscale=-1.000,yscale=1.000,draw=black,fill=black,line join=miter,line
cap=round,miter limit=4.00,nonzero rule,dash phase=3.000pt,line
width=0.000pt,rounded corners=0.0000cm] (-182.0794,658.5070) rectangle
(-177.1244,660.6401);
\path[xscale=-1.000,yscale=1.000,draw=black,fill=black,line join=miter,line
cap=round,nonzero rule,dash phase=3.000pt,line width=0.000pt,rounded
corners=0.0000cm] (-280.8165,679.2454) rectangle (-193.6939,684.6964);
\path[xscale=-1.000,yscale=1.000,fill=black,nonzero rule,rounded
corners=0.0000cm] (-280.8165,694.2955) rectangle (-177.1245,696.3244);
\path[xscale=-1.000,yscale=1.000,draw=black,fill=black,line join=miter,line
cap=round,miter limit=4.00,nonzero rule,dash phase=3.000pt,line
width=0.000pt,rounded corners=0.0000cm] (-280.8165,716.4833) rectangle
(-177.1245,721.9073);
\path[xscale=-1.000,yscale=1.000,draw=black,fill=black,line join=miter,line
cap=round,nonzero rule,dash phase=3.000pt,line width=0.000pt,rounded
corners=0.0000cm] (-185.6345,669.1724) rectangle (-177.1244,673.9126);
\end{tikzpicture}
}
\\

into the box for the chapter headers with the same height and the width     scaled accordingly, so the image is not distorted.


\end{document}  

It would be very nice if you could teach me how to do this! It would be preferable if the logo would always appear at the left border of the box (left page border) for the chapter header, and I could individually scale its size.

marked as duplicate by JPi, Mensch, Stefan Pinnow, CarLaTeX, Maarten Dhondt Jan 30 '17 at 18:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Nesting tikzpictures can work, but can fail too. See e.g. tex.stackexchange.com/questions/47377/…. I would normally store the internal picture first in some box and then use this box. – Ulrike Fischer Jan 30 '17 at 11:25
  • Thank you for this hint. I tried to define a box for the internal picture, but i can´t figure out where and how to put it into my code to make it appear at the left boarder of the outer box/ Tikz picture? And i do not understand how to scale the size of the inner picture? – NorrinRadd Jan 30 '17 at 12:56
  • is it possible to position the inner picture relative to the existing node? This do not need to be two separate Tikz pictures, all i need is to be able to control their color and size individually. – NorrinRadd Jan 30 '17 at 13:29
  • You already have one tikzpicture inside another simply to move one rectangle to (current page.north west). Anyway, I'm having trouble with all the fontenc stuff and can't run your MWE. – John Kormylo Jan 30 '17 at 16:27
2

Since all the elements have the same y location, I put them into a scope. Note that the resizing and color=white had to be done while defining the savebox. Once a box it set, you can't change it (much).

\documentclass[a4paper,11pt,fleqn]{book}
%\usepackage{fontspec}  % If i disable this and every thing else labled with [A]
%\usepackage[T1]{fontenc}% [A]
%\usepackage[utf8]{inputenc}% not with my editor
\usepackage{xcolor}
\usepackage{color}
\definecolor{mydarkgray}{RGB}{0,100,100}
\newcommand{\mytemplatecolor}{mydarkgray}

\usepackage{tikz}

\newsavebox{\logo}
\savebox{\logo}{\resizebox{!}{15mm}{%
\begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1.000000, xscale=1.000000, inner sep=0pt, outer sep=0pt]
\path[draw=white,fill=white,line join=miter,line cap=round,miter
limit=4.00,nonzero rule,dash phase=3.000pt,line width=0.000pt]
(178.4915,651.0411) .. controls (178.0358,651.0411) and (177.5801,651.0411) ..
(177.1244,651.0411) .. controls (177.1244,652.6787) and (177.1244,654.3163) ..
(177.1244,655.9539) .. controls (177.5801,655.9539) and (178.0358,655.9539) ..
(178.4915,655.9539) .. controls (178.4915,654.3163) and (178.4915,652.6787) ..
(178.4915,651.0411) -- cycle;
\path[xscale=-1.000,yscale=1.000,draw=white,fill=white,line join=miter,line
cap=round,miter limit=4.00,nonzero rule,dash phase=3.000pt,line
width=0.000pt,rounded corners=0.0000cm] (-182.0794,658.5070) rectangle
(-177.1244,660.6401);
\path[xscale=-1.000,yscale=1.000,draw=white,fill=white,line join=miter,line
cap=round,nonzero rule,dash phase=3.000pt,line width=0.000pt,rounded
corners=0.0000cm] (-280.8165,679.2454) rectangle (-193.6939,684.6964);
\path[xscale=-1.000,yscale=1.000,fill=white,nonzero rule,rounded
corners=0.0000cm] (-280.8165,694.2955) rectangle (-177.1245,696.3244);
\path[xscale=-1.000,yscale=1.000,draw=white,fill=white,line join=miter,line
cap=round,miter limit=4.00,nonzero rule,dash phase=3.000pt,line
width=0.000pt,rounded corners=0.0000cm] (-280.8165,716.4833) rectangle
(-177.1245,721.9073);
\path[xscale=-1.000,yscale=1.000,draw=white,fill=white,line join=miter,line
cap=round,nonzero rule,dash phase=3.000pt,line width=0.000pt,rounded
corners=0.0000cm] (-185.6345,669.1724) rectangle (-177.1244,673.9126);
\end{tikzpicture}}}

\usepackage[explicit]{titlesec}
\newcommand*\chapterlabel{}
\titleformat{\chapter}[display]  % type (section,chapter,etc...) to vary,  shape (eg display-type)
%{\normalfont\bfseries\Huge} % and enable this ander very the other line   labled with [B] 
{\Huge\bfseries\sffamily\color{\mytemplatecolor}}%\fontspec[]{MetaBoldLF-Roman}} % [A]
{\gdef\chapterlabel{\thechapter\ }}     % the label 
{0pt} % separation between label and chapter-title
{\begin{tikzpicture}[remember picture, overlay]
  \path (current page.north west) ++(0pt,-7.2cm) coordinate(title);
  \begin{scope}[shift=(title)]
    \draw[fill=\mytemplatecolor,\mytemplatecolor] (0,0) rectangle (35.5mm,-15mm);% Neu um es grau zu machen
    \node[anchor=north west,inner sep=0pt] {\usebox{\logo}};
    \node[anchor=north east,xshift=34mm,minimum height=30mm,inner sep=0mm]
    {\parbox[top][30mm][t]{15mm}{\raggedleft $\phantom{\textrm{l}}$\color{white}\chapterlabel}};  %the black l is just to get better base-line alingement
    \node[anchor=north west,xshift=37mm,text width=\textwidth,minimum height=30mm,inner sep=0mm]
    {\parbox[top][30mm][t]{\textwidth}{\color{\mytemplatecolor}#1}};
  \end{scope}
 \end{tikzpicture}
\gdef\chapterlabel{}
} % code before the title body
\titlespacing*{\chapter}{-98pt}{38pt}{30pt} % [A]
%\titlespacing*{\chapter}{0pt}{50pt}{30pt} %[B]  than i do not need any offse here?
\begin{document}
\chapter{A Chapter} 

\end{document}   

demo

  • Hi that is pretty close to what i want. I should explain myself better next time. The result should look like this sketch: !Logo. The Logo should be scaled to the height of the Box, but its width should be sacled accordingly so it isn´t distorted. It would be even better if i could controll the width of the Logo indivudually ,wich is what i did in the sketch.The size and the position of the Box need to stay the same as they should appear next to the Chapter heading! Thank you for your time btw! – NorrinRadd Jan 31 '17 at 8:30
  • the width of the box needs to be at the defined sizes as it corresponds to the size of the page margin. With this in mind.... The logo will need to be scaled slightly . I wasn´t really aware of this until now. – NorrinRadd Jan 31 '17 at 9:59
  • I posted an additional question here additional question. – NorrinRadd Jan 31 '17 at 11:26
  • I revised the solution. BTW, the chapter number overlaps the logo slightly. – John Kormylo Jan 31 '17 at 15:19

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