새로운 PGF 노드 모양 안에 잘린 채굴 환경

Sep 11 2020

PGF에서 파일 또는 페이지와 같은 노드 모양을 만들고 그 모양으로 주조 된 환경을 만들고 싶습니다. 아래 이미지를 참조하십시오.

몇 가지 문제가 있습니다. 하나는 텍스트가 아래쪽과 오른쪽의 테두리 위에 그려지는 것입니다. 다른 하나는, 예를 들어 생성 된 환경의 내용을 0.5만큼 확장 할 수 있기를 원한다는 것입니다. 또한 모든 주조 된 재료를 노드 또는 모양에 대한 속성으로 제공 \node [draw, shape=document, minted={python,class.py}] {};할 수 있다면 좋겠지 만 가능하지 않다면 해결하겠습니다. 나는 어떤 식 으로든 미니 페이지 구현에 연결되어 있지 않습니다.

테두리의 텍스트의 경우 현재 선 너비를 미니 페이지 치수에서 뺄 수 있다고 생각합니다. 스케일링을 위해 미니 페이지 내부에 스케일 박스를 시도했지만 생성 된 축 어적 환경이 실패했습니다. 나는 생성 된 매개 변수를 노드에 속성으로 전달하는 방법을 정말로 모른다.

이행:

\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}

답변

2 Ignasi Sep 11 2020 at 15:40

목록을 자르는 tcolorbox방법을 모르지만 비슷한 작업을 할 수 있습니다 .

\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}