2

I'm trying to define a document where I have different levels of it contained in TikZ boxes as shown below; the idea is that each box should get a color depending on the value of the counter (which is displayed inside the circle positioned on the top of each rectangle). document structure Here is an extract of my code:


documentclass[10pt]{book}

\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{engrec}
\usepackage{yfonts}

%\usepackage[a4paper, inner=1cm, width=19cm, top=1cm, bottom=2cm, marginpar=0pt, twoside, showframe]{geometry}
\usepackage[a4paper, inner=1cm, width=19cm, top=1cm, bottom=2cm, marginpar=0pt, twoside]{geometry}

\usepackage{xparse}
\usepackage{xcolor}
\usepackage{xspace}

\usepackage{ifthen}

\usepackage{environ}

\usepackage{tikz}
\usetikzlibrary{
    positioning,
    fit,
    arrows,
    arrows.meta,
    intersections,
    decorations,
    backgrounds,
    calc,
    math,
    through,
    shapes,
    shadows,
    decorations.pathmorphing
}

\usepackage{lipsum}

\setmainfont{Tisa OT}
\setsansfont{TeX Gyre Heros Cn}
\setdefaultlanguage{italian}

\definecolor{conceptcolor}{RGB}{160,44,90}
\definecolor{subconceptcolora}{RGB}{255,102,0}
\definecolor{subconceptcolorb}{RGB}{95,95,211}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                           %
%       CONCEPT BOX         %
%                           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{conceptctr}
\renewcommand{\theconceptctr}{\Alph{conceptctr}}

\tikzstyle{conceptboxtitlesty} = 
    [
        circle,%
        draw = conceptcolor,%
        line width = 0.7mm,%
        node font = \Huge\bfseries\sffamily,%
        text = conceptcolor,%
        fill = white,%
        inner sep = 3pt%
    ]
\tikzstyle{conceptboxsty} = 
    [
        rectangle,
        rounded corners = 10pt,%
        draw = conceptcolor,
        line width = 0.7mm,%
        node font = \small
    ]
%
\NewEnviron{conceptbox}{
    \stepcounter{conceptctr}
    \begin{tikzpicture}
        \node[conceptboxsty, anchor=north west](concepttext) at (-6,0) {
            \begin{minipage}{18cm}
                \vspace{20pt}
                \BODY
            \end{minipage}
            \vspace{20pt}
        };
        \node[conceptboxtitlesty, xshift = 2cm](conecepttitle) at (concepttext.north west){\theconceptctr};

    \end{tikzpicture}
}[\newline]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                           %
%      SUBCONCEPT BOX       %
%                           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{subconceptctr}[conceptctr]
\renewcommand{\thesubconceptctr}{\arabic{subconceptctr}}
\newcommand{\subconceptcolor}[1]
    {%
       \ifthenelse{#1 = 1}%
          {subconceptcolora}%
            {%
                \ifthenelse{#1 = 2}%
                {subconceptcolorb}%
                {}%% &c.
            }%
    }

\tikzstyle{subconcepttitlesty} = 
    [
        circle,%
        draw = \currentcolor,%
        line width = 0.5mm,%
        node font = \LARGE\bfseries\sffamily,%
        text = \currentcolor,%
        fill = white,%
        inner sep = 3pt%
    ]
    \tikzstyle{subconceptboxsty} = 
    [
        rectangle,
        rounded corners = 10pt,%
        draw = \currentcolor,
        line width = 0.5mm,%
        node font = \small%
    ]
%
\newcommand{\currentcolor}{}
\NewEnviron{subconceptbox}{
    \stepcounter{subconceptctr}
    \renewcommand{\currentcolor}{\subconceptcolor{\value{subconceptctr}}}
    \begin{tikzpicture}
        \node[subconceptboxsty,
            anchor=north west,
            ](subconcepttext) at (0,-1) {
            \begin{minipage}{17.5cm}
                \vspace{20pt}
                \BODY
                \vspace{10pt}
            \end{minipage}
        };%
        \node[subconcepttitlesty,
            anchor = center,
            xshift = 2cm, yshift = 0cm](subconecepttitle) at (subconcepttext.north west){\thesubconceptctr};%
    \end{tikzpicture}
}[\newline]

\begin{document}
    \begin{conceptbox}
        Il C. è \textsl{similitudo rei in mente expressa} (cioè la rappresentazione di una cosa espressa nella mente). Infatti, essa è il prodotto dell' \textsl{apprensione}, ovvero della prima operazione della mente che astrae, mediante i sensi, una rappresentazione universale di ciò che si osserva fuori di noi.\\\newline

        \begin{subconceptbox}
            Il C. ci rimanda immediatamente alla realtà e non allo stesso C. Esso significa ciò che la cosa è secondo un aspetto determinato (i.e., il concetto di "relazione" ci porta a capire cos' è una relazione; quello di "tartaruga", a capire cos' è una tartaruga). Ciò non implica una totale comprensione della natura, né che siamo capaci di definirla, ma senz' altro comporta una certa intellezione.
        \end{subconceptbox}

        \begin{subconceptbox}
            Ciò che caratterizza il C. è la sua \textit{\textbf{Universalità}}: quanto è espresso dal C. vale per tutti e per sempre, grazie al fatto che considera tutte le note essenziali che tutti gl' individui devono possedere. Grazie all' Universalità abbiamo i seguenti risultati:\par%            
        \end{subconceptbox}

    \end{conceptbox}
\end{document}

I had a look at this question: How to pass parameters to \tikzstyle?; and these If-then-else inside TikZ graph?, If-then-else inside TikZ graph?.
So my understanding is that the \ifthenelse command is not recognized by TikZ; for this reason I've tried to pass the value of the conditional to a variable (\currentcolor) which, I thought, would have been initialized before calling the tikzpicture environment.
Still, what I get is a bunch (166) errors during compilation.
Any suggestion? Thank you for you support.

Guidone
  • 127
  • You should post a complete document that can be TeXed, even if with errors. It looks like you have posted (most of?) the preamble. What is needed, in addition is a \begin{document}...\end{document} block showing how you want to use the code. That will spark more interest. – sgmoye Feb 28 '20 at 12:59
  • Thank you @sgmoye, I just added as advised. – Guidone Feb 28 '20 at 13:47
  • After having further and better analysed the compiler log, I' ve noticed the following message as first error:
    prova3.tex:277: Undefined control sequence.
    \TE@repl #1#2->\long \def \@tempc 
                                      ##1#1##2{\def \@tempa {##2}\def \@tempb {\...
    l.277     \end{conceptbox}
    

    So \ifthen, for some to-me-unknown reason, is called within TikZ (?)

    – Guidone Feb 28 '20 at 14:01

1 Answers1

2

\tikzstyle is deprecated. I do not have your fonts installed, but they are not relevant to the problem. \ifthen is not expandable, but in the case at hand you only need \ifodd. For more complex situations you can use pgf to define the color.

\documentclass[10pt]{book}
\usepackage[a4paper, inner=1cm, width=19cm, top=1cm, bottom=2cm, marginpar=0pt, twoside]{geometry}

\usepackage{environ}

\usepackage{tikz}
\usetikzlibrary{
    positioning,
    fit,
    arrows,
    arrows.meta,
    intersections,
    decorations,
    backgrounds,
    calc,
    math,
    through,
    shapes,
    shadows,
    decorations.pathmorphing
}

\usepackage{lipsum}
\definecolor{conceptcolor}{RGB}{160,44,90}
\definecolor{subconceptcolora}{RGB}{255,102,0}
\definecolor{subconceptcolorb}{RGB}{95,95,211}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                           %
%       CONCEPT BOX         %
%                           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{conceptctr}
\renewcommand{\theconceptctr}{\Alph{conceptctr}}

\tikzset{conceptboxtitlesty/.style={
        circle,%
        draw = conceptcolor,%
        line width = 0.7mm,%
        node font = \Huge\bfseries\sffamily,%
        text = conceptcolor,%
        fill = white,%
        inner sep = 3pt%
    },
conceptboxsty/.style={
        rectangle,
        rounded corners = 10pt,%
        draw = conceptcolor,
        line width = 0.7mm,%
        node font = \small
    }}
%
\NewEnviron{conceptbox}{
    \stepcounter{conceptctr}
    \begin{tikzpicture}
        \node[conceptboxsty, anchor=north west](concepttext) at (-6,0) {
            \begin{minipage}{18cm}
                \vspace{20pt}
                \BODY
            \end{minipage}
            \vspace{20pt}
        };
        \node[conceptboxtitlesty, xshift = 2cm](conecepttitle) at (concepttext.north west){\theconceptctr};

    \end{tikzpicture}
}[\newline]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                           %
%      SUBCONCEPT BOX       %
%                           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{subconceptctr}[conceptctr]
\renewcommand{\thesubconceptctr}{\arabic{subconceptctr}}

\tikzset{subconcepttitlesty/.style={
        circle,%
        draw = \currentcolor,%
        line width = 0.5mm,%
        node font = \LARGE\bfseries\sffamily,%
        text = \currentcolor,%
        fill = white,%
        inner sep = 3pt%
    },
subconceptboxsty/.style={
        rectangle,
        rounded corners = 10pt,%
        draw = \currentcolor,
        line width = 0.5mm,%
        node font = \small%
    }}
%
\newcommand{\currentcolor}{}

\NewEnviron{subconceptbox}{
    \stepcounter{subconceptctr}
    \ifodd\value{subconceptctr}
    \renewcommand{\currentcolor}{subconceptcolora}
    \else
    \renewcommand{\currentcolor}{subconceptcolorb}
    \fi
    \begin{tikzpicture}
        \node[subconceptboxsty,
            anchor=north west,
            ](subconcepttext) at (0,-1) {
            \begin{minipage}{17.5cm}
                \vspace{20pt}
                \BODY
                \vspace{10pt}
            \end{minipage}
        };%
        \node[subconcepttitlesty,
            anchor = center,
            xshift = 2cm, yshift = 0cm](subconecepttitle) at (subconcepttext.north west){\thesubconceptctr};%
    \end{tikzpicture}
}[\newline]

\begin{document}
    \begin{conceptbox}
        Il C. \`e \textsl{similitudo rei in mente expressa} (cio\`e la
        rappresentazione di una cosa espressa nella mente). Infatti,
        essa \`e il prodotto dell' \textsl{apprensione}, ovvero della
        prima operazione della mente che astrae, mediante i sensi, una
        rappresentazione universale di ci\`o che si osserva fuori di noi.\\\newline

        \begin{subconceptbox}
            Il C. ci rimanda immediatamente alla realt\`a e non allo stesso C.
Esso significa ci\`o che la cosa e secondo un aspetto determinato (i.e., il
concetto di "relazione" ci porta a capire cos' \`e una relazione; quello di
"tartaruga", a capire cos' \`e una tartaruga). Ci\`o non implica una totale
comprensione della natura, n\'e che siamo capaci di definirla, ma senz' altro
comporta una certa intellezione.
        \end{subconceptbox}

        \begin{subconceptbox}
            Cio che caratterizza il C. \`e la sua
\textit{\textbf{Universalit\'a}}: quanto \`e espresso dal C. vale per tutti e
per sempre, grazie al fatto che considera tutte le note essenziali che tutti gl'
individui devono possedere. Grazie all' Universalita abbiamo i seguenti
risultati:\par%            
        \end{subconceptbox}

\end{conceptbox}
\end{document}

enter image description here

Note that using tcolorbox will be a much better way to create these frames. This answer is only to remove the error from the code, not to provide a tcolorbox code, which I however think will make more sense.