Abgeschnittene geprägte Umgebung innerhalb einer neuen PGF-Knotenform

Abgeschnittene geprägte Umgebung innerhalb einer neuen PGF-Knotenform

Ich möchte eine datei- oder seitenähnliche Knotenform in PGF erstellen und eine geprägte Umgebung in diese Form einfügen. Siehe das Bild unten:

Bildbeschreibung hier eingeben

Es gibt ein paar Probleme. Eines ist, dass der Text unten und rechts über den Rand gezeichnet wird. Das andere ist, dass ich den Inhalt der geprägten Umgebung gerne um beispielsweise 0,5 skalieren könnte. Ich fände es auch gut, wenn ich den gesamten geprägten Kram als Attribut für den Knoten oder die Form bereitstellen könnte, so etwas wie \node [draw, shape=document, minted={python,class.py}] {};, aber ich würde mich damit zufrieden geben, wenn das nicht möglich ist. Ich bin in keiner Weise an die Minipage-Implementierung gebunden.

Ich denke, für den Text am Rand könnte die aktuelle Linienbreite wahrscheinlich von den Minipage-Abmessungen abgezogen werden. Ich habe eine Scalebox innerhalb der Minipage zum Skalieren ausprobiert, aber die geprägten wörtlichen Umgebungen haben dort versagt. Ich habe wirklich keine Ahnung, wie ich die geprägten Parameter möglicherweise als Attribut an den Knoten übergeben kann.

Implementierung:

\documentclass{standalone}

\usepackage{minted}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}

\renewcommand{\familydefault}{\sfdefault}

\begin{filecontents}{class.py}
class MyClass:
    variable = "blah"

    def function(self):
        print("This is a message inside the class.")

myobjectx = MyClass()

myobjectx.variable
\end{filecontents}

\makeatletter
\pgfdeclareshape{document}{
  \inheritsavedanchors[from=rectangle] % this is nearly a rectangle
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}
  % ... and possibly more
  \backgroundpath{% this is new
    % store lower right in xa/ya and upper right in xb/yb
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    % compute corner of ‘‘flipped page’’
    \pgf@xc=\pgf@xb \advance\pgf@xc by-7.5pt % this should be a parameter
    \pgf@yc=\pgf@yb \advance\pgf@yc by-7.5pt
    % construct main path
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathclose
    % add little corner
    \pgfpathmoveto{\pgfpoint{\pgf@xc}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
    \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
  }
}
\makeatother

\begin{document}

\begin{tikzpicture}

  \node [draw, line width=3pt, shape=document] {\begin{minipage}[t][1cm][t]{4cm}\inputminted{python}{class.py}\end{minipage}};

\end{tikzpicture}

\end{document}

Antwort1

Etwas Ähnliches kann mit gemacht werden tcolorbox, obwohl ich nicht weiß, wie man die Auflistung ausschneidet.

\documentclass{article}
\usepackage[most, minted]{tcolorbox}

\tcbset{
    mylisting/.style={
        listing engine=minted, minted style=trac,
        minted language=python, listing only,
        enhanced,
        boxrule=1mm,
        colback=yellow!50,
        colframe=yellow!20!black,
        sharp corners,rounded corners=northeast,arc is angular,arc=3mm,
        underlay={%
            \path[fill=tcbcolback] ([yshift=-3mm]interior.north east)-|([xshift=-3mm]interior.north east);
            \path[draw=tcbcolframe, shorten <=-0.5mm,shorten >=-0.5mm, line width=1mm] ([yshift=-3mm]interior.north east)-|([xshift=-3mm]interior.north east);},
        #1
    }
}

\begin{filecontents}{class.py}
class MyClass:
    variable = "blah"

    def function(self):
        print("This is a message inside the class.")

myobjectx = MyClass()

myobjectx.variable
\end{filecontents}

\begin{document}
\tcbinputlisting{mylisting, listing file=class.py}
\end{document}

Bildbeschreibung hier eingeben

verwandte Informationen