하나의 멋진 프레임에 두 개의 열이 있는 목록

하나의 멋진 프레임에 두 개의 열이 있는 목록

나 좀 가지고 놀고 있어lstlistings그리고 내 모든 목록에 대해 그러한 일이 가능한지 궁금합니다.

목록

이런 일을 달성하는 방법은 무엇입니까?

참고: 저는 모든 목록에 적용할 수 있고(예를 들어 새 명령을 정의하여) 두 열의 균형을 자동으로 조정할 수 있는 솔루션을 찾고 있습니다.

답변1

그만큼listingsmulticol패키지는 패키지 와 원활하게 상호 작용할 수 있습니다.. 프레임 작업 tcolorboxlistings. 전환되는 것 같습니다!

숫자를 강조하는 아이디어는 다음에서 따왔습니다.곤잘로의 답변.

여기에 이미지 설명을 입력하세요

\documentclass[landscape]{article}
\usepackage[margin = 2cm, includeheadfoot]{geometry}
\usepackage{lmodern}
\usepackage{multicol}
\usepackage{tcolorbox}
\tcbuselibrary{skins,listings}
\newtcblisting{mycpptwocol}[1][]{%
  enhanced,
  arc = 0pt,
  outer arc = 0pt,
  colback = blue!5,
  colframe = blue!50!black,
  listing only,
  fonttitle = \bfseries,
  listing options = {%
    language = C++,
    basicstyle = \ttfamily,
    multicols = 2,
    numbers = left,
    xleftmargin = 1em,
    showstringspaces = false,
  },
  overlay = {%
    \fill[gray!30] 
      (interior.north west)
      rectangle 
      ([xshift = 2em]interior.south west);
    \fill[gray!30] 
      ([xshift = -1em]interior.north)
      rectangle 
      ([xshift = 1em]interior.south);
    \draw[ultra thick, blue!50!black]
      ([xshift = -1em]interior.north) -- 
      ([xshift = -1em]interior.south); 
  },
  /utils/exec = {%
    \def\thelstnumber{%
      \texttt{\csname two@digits\endcsname{\the\value{lstnumber}}}}},
  title = {\centering\ttfamily #1}
}
\begin{document}

\begin{mycpptwocol}[helloworld.cpp]
#include <iostream>

int main()
{
    std::cout<<"Hello World``;
    return 0;
}
// This is a second column, just
// for fun !!!
\end{mycpptwocol}
\end{document}

편집하다요청한 대로 앞에 0이 두 개 있는 버전입니다. 참고로 는 핵심 \two@digits매크로 LaTeX( 참조 texdoc source2e)이며 \three@digits존재하지 않습니다(그래서 정의했지만 다시 문제가 발생할 수 있습니다 \makeatletter).

\documentclass[landscape]{article}
\usepackage[margin = 2cm, includeheadfoot]{geometry}
\usepackage{lmodern}
\usepackage{multicol}
\usepackage{tcolorbox}
\tcbuselibrary{skins,listings}
\makeatletter
\def\three@digits#1{\ifnum#1<10 00\else\ifnum#1<100 0\fi\fi\number#1}
\makeatother
\newtcblisting{mycpptwocol}[1][]{%
  enhanced,
  arc = 0pt,
  outer arc = 0pt,
  colback = blue!5,
  colframe = blue!50!black,
  listing only,
  fonttitle = \bfseries,
  listing options = {%
    language = C++,
    basicstyle = \ttfamily,
    multicols = 2,
    numbers = left,
    xleftmargin = 1.5em,
    showstringspaces = false,
  },
  overlay = {%
    \fill[gray!30] 
      (interior.north west)
      rectangle 
      ([xshift = 2.5em]interior.south west);
    \fill[gray!30] 
      ([xshift = -1em]interior.north)
      rectangle 
      ([xshift = 1.5em]interior.south);
    \draw[ultra thick, blue!50!black]
      ([xshift = -1em]interior.north) -- 
      ([xshift = -1em]interior.south); 
  },
  /utils/exec = {%
    \def\thelstnumber{%
      \texttt{\csname three@digits\endcsname{\the\value{lstnumber}}}}},
  title = {\centering\ttfamily #1}
}
\begin{document}

\begin{mycpptwocol}[helloworld.cpp]
#include <iostream>

int main()
{
    std::cout<<"Hello World``;
    return 0;
}
// This is a second column, just
// for fun !!!
//
\end{mycpptwocol}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보