
내 코드의 일부를 강조하기 위해 몇 가지 새로운 명령을 정의하고 싶습니다. 이는 실제로 프로그래밍 언어가 아닌 추적 덤프를 위한 것입니다.
내 문제는 컬러 텍스트를 목록 텍스트와 제대로 정렬할 수 없는 것 같다는 것입니다. "Hello worlds"를 참조하세요.
새 명령 정의에 추가하려고 시도했지만 \ttfamily
도움이 되지 않았습니다. 또한 다른 글꼴 크기를 시도했는데 색상이 있는 텍스트 글꼴과 색상이 없는 텍스트 글꼴이 모두 같은 크기이므로 문제가 되지 않는다고 생각합니다.
\documentclass{article}
\usepackage{listings}
\lstset{
basicstyle=\ttfamily\large,
breakatwhitespace=false,
breaklines=true,
escapeinside={\%*}{*},
}
\usepackage{color}
\definecolor{mycolorGreenOne}{rgb}{0, 0.7, 0}
\newcommand*{\listingsHigh}[1]{\textcolor{red}{#1}}
\newcommand*{\LighthighOne}{\color{cyan}}
\begin{document}
\begin{lstlisting}
My text: %*\LighthighOne Hello world!* Goodbye!
My text: Hello world! Goodbye!
My text: %*\listingsHigh{Hello world!}* Goodbye!
\end{lstlisting}
\end{document}
답변1
문제를 해결했습니다! 나는 다음을 추가했다: columns=fullflexible
.
문서에 있는 fullflexible에 대한 설명은 실제로 수행되는 작업과 관련하여 나에게는 직관에 어긋나는 것 같습니다. 이는 고정이 열을 "정렬" 상태로 유지하고 유동이 열을 "파기"하여 원래 글꼴 정렬이 유지되는지 확인하기 때문입니다. 그러나 fixed
작동하지는 않지만 fullflexible
작동합니다. 누군가가 이유를 설명하고 싶어한다면 감사하겠습니다.
섹션 2.10을 참조하세요.목록 pdf.
\documentclass{article}
\usepackage{listings}
\lstset{
basicstyle=\ttfamily\large,
breakatwhitespace=false,
breaklines=true,
escapeinside={\%*}{*},
columns=fullflexible
}
\usepackage{color}
\definecolor{mycolorGreenOne}{rgb}{0, 0.7, 0}
\newcommand*{\listingsHigh}[1]{\textcolor{red}{#1}}
\newcommand*{\LighthighOne}{\color{cyan}}
\begin{document}
\begin{lstlisting}
My text: %*\LighthighOne Hello world!* Goodbye!
My text: Hello world! Goodbye!
My text: %*\listingsHigh{Hello world!}* Goodbye!
\end{lstlisting}
\end{document}