我正在使用 Latex 列表包在我的文档中添加源代码,但问题是左侧缺少一些字符,如图所示。
\usepackage{listings}
源代码
\begin{adjustwidth}{6em}{3em}
\lstset{frame=shadowbox,captionpos=b,rulesepcolor=\color{black},identifierstyle=\color{black},caption= Java Class ,label=foo,numbers=left} \begin{lstlisting}
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
\end{lstlisting}
\end{adjustwidth}
是否有任何命令可以转移源代码? 如有任何建议我们将不胜感激?
主文件
\documentclass[letter,14pt,landscape,a4paper]{book} %{article}
\input{inc/page_style}
\input{foo}
\end{document}
页面样式
%\documentclass[11pt,letter,landscape] {article}%{amsart}
%\usepackage{inc/weekly_calendar}
\usepackage{inc/monthly_calendar}%Comment week_calender
\let\proof\relax
\let\endproof\relax
\usepackage{amsmath,amssymb}
%\usepackage{inc/xymtex}
\usepackage{units}
%\usepackage{inc/chemstr}
\usepackage{scrextend}
\usepackage{graphicx}
\usepackage{inc/example}
\changefontsizes{14pt}
\usepackage{longtable}
\usepackage{lipsum}
\usepackage[normalem]{ulem} % either use this (simple) or
\usepackage{soul} % use this (many fancier options)
\usepackage{pdfcomment}
\usepackage[inline]{inc/trackchanges}
\addeditor{Nivir}
\usepackage{cancel}
\usepackage[normalem]{ulem}
\usepackage{paralist}
\usepackage{soul}
\usepackage{hyperref}
\usepackage{chngpage}
\usepackage{listings}
\usepackage[inline]{enumitem}
\usepackage{color}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{frame=shadowbox, rulesepcolor=\color{black}}
\lstset{
basicstyle=\ttfamily\scriptsize{150pt},%basicstyle=\ttfamily\scriptsize,
keywordstyle=\color{blue}\ttfamily,
stringstyle=\color{red}\ttfamily,
commentstyle=\color{green}\ttfamily,
language=c,
gobble=4,
basicstyle=\scriptsize,
upquote=true,
aboveskip={2.5\baselineskip},
columns=fullflexible,
showstringspaces=false,
extendedchars=true,
breaklines=true,
showtabs=false,
showspaces=false,
showstringspaces=false,
identifierstyle=\ttfamily,
keywordstyle=\color[rgb]{0,0,1},
commentstyle=\color[rgb]
{0.133,0.545,0.133},stringstyle=\color[rgb]{0.627,0.126,0.941},
}
\hypersetup{
bookmarks=true, % show bookmarks bar?
unicode=false, % non-Latin characters in Acrobat’s bookmarks
pdftoolbar=true, % show Acrobat’s toolbar?
pdfmenubar=true, % show Acrobat’s menu?
pdffitwindow=false, % window fit to page when opened
pdfstartview={FitH}, % fits the width of the page window
pdftitle={My title}, % title
pdfauthor={Author}, % author
pdfsubject={Subject}, % subject of the document
pdfcreator={Creator}, % creator of the document
pdfproducer={Producer}, % producer of the document
pdfkeywords={keyword1} {key2} {key3}, % list of keywords
pdfnewwindow=true, % links in new window
colorlinks=true, % false: boxed links; true: colored links
linkcolor=blue, % color of internal links (box color)
citecolor=green, % color of links to bibliography
filecolor=blue, % color of file links
urlcolor=blue % color of external links %cyan
}
\usepackage{color, colortbl}
\definecolor{Gray}{gray}{0.9}
%\definecolor{LightCyan}{rgb}{0.88,1,1}
\definecolor{Gray}{gray}{0.9}
\definecolor{LightCyan}{rgb}{0,1,1}
\usepackage[first=0,last=9]{lcg}
\newcommand{\ra}{\rand0.\arabic{rand}}
\usepackage{fancybox}
\usepackage{datetime}
\usepackage{enumitem}
\setlist{nolistsep}
\usepackage{listings}
\usepackage[inline]{inc/trackchanges}
\addeditor{N} %adding comments
\usepackage{bbding}
\usepackage{longtable}
\usepackage[landscape,margin=0.4in]{geometry}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{hyperref} %bookmarks
\usepackage{verbatim}
%\usepackage[T1]{fontenc}
\usepackage{fourier} %setting font
%\pagecolor{lightgray} %page background
\usepackage{scrextend}
\changefontsizes{11pt}
\usepackage{lipsum}
\definecolor{bookColor}{cmyk}{90,0,0,1.90}%0.90\%black
\definecolor{oddcolumnscolor}{rgb}{0.93,0.93,0.93} %long table
\usepackage{color}
\usepackage{enumitem}
%\hypersetup{linkcolor=blue}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains, calc}
%--------------------------------------------Fancy Heading
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\usepackage{xcolor}
\newcommand{\chapnumfont}{% % define font for chapter number
\usefont{T1}{pnc}{b}{n}% % choose New Chancery, bold, normal shape
\fontsize{70}{70}% % font size 100pt, baselineskip 100pt
\selectfont% % activate font
}
\colorlet{chapnumcol}{gray!75} % color for chapter number
\titleformat{\chapter}[display]
{\filleft\bfseries}
{\filleft\chapnumfont\textcolor{chapnumcol}{\thechapter}}
{-15pt}
{\Huge}
%--------------------------------------------
% display page numbers in the headings. Start with roman numerals %
\pagenumbering{arabic}%comment if you to start from index from the TOC
\setcounter{page}{1}%comment if you to start from index from the TOC
%--------------------------------------------Remove the empty pages between chapter
\let\cleardoublepage\clearpage
%--------------------------------------------
\begin{document}
%--------------------------------------------
\pagestyle{empty}
\noindent
\StartingDayNumber=2 % Calendar start:1=Sunday, 2=Monday
\begin{center}
\vspace{-8mm}
\textsc{\large {\color{blue}\textbf{Schedule Roy \ArrowBoldDownRight }}}
\textsc{\large {\color{blue}\textbf{Daily, Weekly, Monthly, Administration}}}\\
\rule[10mm]{12.0cm}{1mm}
\vspace{-1.5mm} %ruller {}{long}{width}
%\line(3,0){250}
\end{center}
%\tableofcontents
%\usepackage[table]{xcolor} % loads also »colortbl«
%\usepackage[table]{xcolor}
%\definecolor{lightgray}{gray}{0.9}
foo.tex
\begin{adjustwidth}{6em}{3em}
\lstset{frame=shadowbox,captionpos=b,rulesepcolor=\color{black},identifierstyle=\color{black},caption= Java Class ,label=foo,numbers=left} \begin{lstlisting}
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
\end{lstlisting}
\end{adjustwidth}
答案1
您的问题出在这一行page_style
:
gobble=4,
这会占用代码块中每行开头的 4 个空格。
gobble=⟨number⟩
吞噬每个开头的 ⟨number⟩ 个字符环境
\lstinline
代码行。此键对或无效\lstinputlisting
。