From 9394103e42aec8d8348ad0c19e70c0fd635d3e3c Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 16 Sep 2020 14:35:21 +0200 Subject: improve how card content is drawn * Card content is always bottom aligned at \contentBottom * Only use one node instead of two to draw \splitcontent * Draw content background relative to the content size * Remove now obsolete \contentsplit variants --- latex/tikzcards.tex | 80 +++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 39 deletions(-) (limited to 'latex/tikzcards.tex') diff --git a/latex/tikzcards.tex b/latex/tikzcards.tex index 3890de4b..e6389f75 100644 --- a/latex/tikzcards.tex +++ b/latex/tikzcards.tex @@ -10,6 +10,9 @@ \pgfmathsetmacro{\strippadding}{0.2} \pgfmathsetmacro{\textpadding}{0.1} \pgfmathsetmacro{\titley}{\cardheight-\strippadding-1.5*\textpadding-0.5*\stripwidth} +\pgfmathsetmacro{\contentTextWidth}{(\cardwidth-2*\strippadding-\stripwidth-2*\textpadding-0.3)*1cm} +\pgfmathsetmacro{\contentLeft}{2*\strippadding + \stripwidth + \textpadding} +\pgfmathsetmacro{\contentBottom}{1 + \textpadding} % Formen der einzelnen Kartenelemente/-bestandteile @@ -19,9 +22,22 @@ \def\shapeRightStripShortHigh{(\cardwidth-\stripwidth-\strippadding,\cardheight-\strippadding-1) rectangle (\cardwidth-\strippadding,\cardheight+0.2)} \def\shapeRightStripShortLow{(\cardwidth-\stripwidth-\strippadding,-0.2) rectangle (\cardwidth-\strippadding,1)} \def\shapeTitleArea{(2*\strippadding+\stripwidth,\cardheight-\strippadding) rectangle (\cardwidth-2*\strippadding-\stripwidth,\cardheight-2*\stripwidth)} -\def\shapeContentArea{(2*\strippadding+\stripwidth,0.5*\cardheight) rectangle (\cardwidth+0.2,-0.2)} +% macro to get the height of an node +% https://tex.stackexchange.com/questions/554237/how-can-i-get-the-height-of-a-tikz-node-and-store-it-in-a-length +\makeatletter % allow use of @ +\NewDocumentCommand {\getnodedimen} {O{\nodewidth} O{\nodeheight} m} { + \begin{pgfinterruptboundingbox} + \begin{scope}[local bounding box=bb@temp] + \node[inner sep=0pt, fit=(#3)] {}; + \end{scope} + \path ($(bb@temp.north east)-(bb@temp.south west)$); + \end{pgfinterruptboundingbox} + \pgfgetlastxy{#1}{#2} +} +\makeatother % end use of @ + % Stylings für die Elemente definieren \tikzset{ % runde Ecken für die Karten @@ -96,47 +112,25 @@ % Inhalt der Karte \newcommand{\cardsplitcontent}[2]{ - \begin{scope}[even odd rule] - \clip[cardcorners] \shapeCard; - \fill[elementcorners,contentbg] \shapeContentArea; - \end{scope} - % \node[draw, below right, text width=(\cardwidth-2*\strippadding-\stripwidth-2*\textpadding-0.3)*1cm] at (2*\strippadding+\stripwidth+\textpadding, 0.5*\cardheight-\textpadding + \heightof{)#1}) { - \node[below right, text width=(\cardwidth-2*\strippadding-\stripwidth-2*\textpadding-0.3)*1cm] at (2*\strippadding+\stripwidth+\textpadding, 0.5*\cardheight-\textpadding + 0.8) { - \textit{\normalsize #1} - }; - \node[below right, text width=(\cardwidth-2*\strippadding-\stripwidth-2*\textpadding-0.3)*1cm] at (2*\strippadding+\stripwidth+\textpadding, 0.5*\cardheight - 0.8) { - \vrule width \textwidth height 2pt \\[-2pt] - \vspace{0.2cm} - {\normalsize #2} - }; -} + % \begin{scope}[even odd rule] + % \clip[cardcorners] \shapeCard; + % \end{scope} -\newcommand{\cardsplitcontentsingleline}[2]{ - \begin{scope}[even odd rule] - \clip[cardcorners] \shapeCard; - \fill[elementcorners,contentbg] \shapeContentArea; - \end{scope} - % \node[draw, below right, text width=(\cardwidth-2*\strippadding-\stripwidth-2*\textpadding-0.3)*1cm] at (2*\strippadding+\stripwidth+\textpadding, 0.5*\cardheight-\textpadding + \heightof{)#1}) { - \node[below right, text width=(\cardwidth-2*\strippadding-\stripwidth-2*\textpadding-0.3)*1cm] at (2*\strippadding+\stripwidth+\textpadding, 0.5*\cardheight-\textpadding) { + % draw content node just to get its dimensions + \node(content)[above right, minimum width=\cardwidth, text width=\contentTextWidth] at (\contentLeft, \contentBottom) { \textit{\normalsize #1} - }; - \node[below right, text width=(\cardwidth-2*\strippadding-\stripwidth-2*\textpadding-0.3)*1cm] at (2*\strippadding+\stripwidth+\textpadding, 0.5*\cardheight - 0.8) { \vrule width \textwidth height 2pt \\[-2pt] \vspace{0.2cm} {\normalsize #2} }; -} -\newcommand{\cardsplitcontenttwolines}[2]{ - \begin{scope}[even odd rule] - \clip[cardcorners] \shapeCard; - \fill[elementcorners,contentbg] \shapeContentArea; - \end{scope} - % \node[draw, below right, text width=(\cardwidth-2*\strippadding-\stripwidth-2*\textpadding-0.3)*1cm] at (2*\strippadding+\stripwidth+\textpadding, 0.5*\cardheight-\textpadding + \heightof{)#1}) { - \node[below right, text width=(\cardwidth-2*\strippadding-\stripwidth-2*\textpadding-0.3)*1cm] at (2*\strippadding+\stripwidth+\textpadding, 0.5*\cardheight-\textpadding + 0.4) { + % draw content background using dimensions of the content node + \getnodedimen{content} + \node[fill=contentbg, above right, elementcorners, minimum height=\nodeheight, minimum width=\nodewidth + 1] at (\contentLeft - \textpadding, \contentBottom) {}; + + % redraw content so it is on top of the background + \node()[above right, minimum width=\cardwidth, text width=\contentTextWidth] at (\contentLeft, \contentBottom) { \textit{\normalsize #1} - }; - \node[below right, text width=(\cardwidth-2*\strippadding-\stripwidth-2*\textpadding-0.3)*1cm] at (2*\strippadding+\stripwidth+\textpadding, 0.5*\cardheight - 0.8) { \vrule width \textwidth height 2pt \\[-2pt] \vspace{0.2cm} {\normalsize #2} @@ -145,11 +139,19 @@ % Inhalt der Karte \newcommand{\cardcontent}[1]{ - \begin{scope}[even odd rule] - \clip[cardcorners] \shapeCard; - \fill[elementcorners,contentbg] \shapeContentArea; - \end{scope} - \node[below right, text width=(\cardwidth-2*\strippadding-\stripwidth-2*\textpadding-0.3)*1cm] at (2*\strippadding+\stripwidth+\textpadding, 3) { + % \begin{scope}[even odd rule] + % \clip[cardcorners] \shapeCard; + % \end{scope} + \node(content)[above right, text width=\contentTextWidth] at (\contentLeft, \contentBottom) { + \textit{\normalsize #1} + }; + + % draw content background using dimensions of the content node + \getnodedimen{content} + \node[fill=contentbg, above right, elementcorners, minimum height=\nodeheight, minimum width=\nodewidth + 1] at (\contentLeft - \textpadding, \contentBottom) {}; + + % redraw content so it is on top of the background + \node[above right, text width=\contentTextWidth] at (\contentLeft, \contentBottom) { \textit{\normalsize #1} }; } -- cgit v1.2.3