彩色单词在列表中重叠且在框外

彩色单词在列表中重叠且在框外

就像主题一样 - “列表中的彩色单词重叠且超出框范围”

我声明如下:

\documentclass[a4paper,12pt,titlepage,headsepline,footsepline,hidelinks]{scrartcl}
    \usepackage[margin=2.5cm]{geometry}
    \usepackage{ucs}
    \usepackage[T1]{fontenc}
    \usepackage[polish]{babel}
    \usepackage[utf8]{inputenc}
    \usepackage{lmodern,scrpage2,lastpage,graphicx,indentfirst,setspace}
    \usepackage{hyperref}
    \usepackage[owncaptions]{vhistory}
    \usepackage{tabularx}
    \usepackage{listings}
    \usepackage{caption}
    \captionsetup{justification=centering}

    \usepackage{color} % additional packages
    \usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
    \definecolor{gainsboro}{HTML}{dcdcdc}
    \definecolor{gainsboro2}{HTML}{f8f8f8}
    \usepackage{listings}
    \lstset{ 
        language=C, % choose the language of the code to colorize code 
        basicstyle=\fontfamily{pcr}\selectfont\footnotesize\color{red},
        keywordstyle=\color{black}\bfseries, % style for keywords
        numbers=none, % where to put the line-numbers
        numberstyle=\tiny, % the size of the fonts that are used for the line-numbers     
        backgroundcolor=\color{gainsboro2},
        showspaces=false, % show spaces adding particular underscores
        showstringspaces=false, % underline spaces within strings
        showtabs=false, % show tabs within strings adding particular underscores
        frame=single, % adds a frame around the code
        tabsize=2, % sets default tabsize to 2 spaces
        rulesepcolor=\color{gray},
        rulecolor=\color{black},
        captionpos=b, % sets the caption-position to bottom
        breaklines=true, % sets automatic line breaking
        breakatwhitespace=false, 
        moredelim=**[is][\color{green}]{@}{@},
        }
    \lstset{  
        %colorize code
    literate={ą}{{\k{a}}}1
                 {Ą}{{\k{A}}}1
                 {ę}{{\k{e}}}1
                 {Ę}{{\k{E}}}1
                 {ó}{{\'o}}1
                 {Ó}{{\'O}}1
                 {ś}{{\'s}}1
                 {Ś}{{\'S}}1
                 {ł}{{\l{}}}1
                 {Ł}{{\L{}}}1
                 {ż}{{\.z}}1
                 {Ż}{{\.Z}}1
                 {ź}{{\'z}}1
                 {Ź}{{\'Z}}1
                 {ć}{{\'c}}1
                 {Ć}{{\'C}}1
                 {ń}{{\'n}}1
                 {Ń}{{\'N}}1 
                 {void}{{{\color{red}void}}}1
                 {main}{{{\color{red}main}}}1
                 {(}{{{\color{blue}(}}}1             
                 %{\)}{{{\color{blue}x}}}1
                 {<}{{{\color{blue}<}}}1
                 {>}{{{\color{blue}>}}}1    
                 {[}{{{\color{blue}[}}}1
                 {]}{{{\color{blue}]}}}1  
                 {=}{{{\color{blue}=}}}1  
                 {\+}{{{\color{blue}+}}}1
                 {\-}{{{\color{blue}\-}}}1   
                 {\;}{{{\color{blue};}}}1         
                 }
    \lstset{breaklines=true,
    basicstyle=\ttfamily}
    \lstset{basewidth=0.5em}
    \lstset{extendedchars=\true}
    \lstset{inputencoding=ansinew}

\开始{文档}

Example:

\begin{lstlisting}
ulong Suma(ulong X,Y)
{
  return(X+Y);
}

void main()
{
  RejestryLong[0]=Suma(1,2);
}
\end{lstlisting}

    \end{document}

但最终我得到了这个:

在此处输入图片描述

如何给框中的单词上色而不产生重叠效果?使用单个字符时我不会遇到这种问题。

答案1

好的,我已经解决了——单词的长度设置正确。

这是正确的:

 {void}{{{\color{red}void}}}4
 {main}{{{\color{red}main}}}4 

相关内容