0

I am using Latex listings package to add the source code in my document, but the problem is on the left side some character is missing as showing in the picture.

\usepackage{listings}

enter image description here

Source Code

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

Is there any command to shift the source code ? Any suggestion will be greatly appreciate ?

MainFile

\documentclass[letter,14pt,landscape,a4paper]{book} %{article}
\input{inc/page_style}
\input{foo}
\end{document}

page_style

%\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
    Could you provide an MWE? – alexwlchan May 5 '14 at 16:47
  • @alexwlchan added the source code. – J4cK May 5 '14 at 17:10
  • 4
    Your snippet doesn't give me the output seen in your image, can you turn it into a complete example demonstrating the problem? – Torbjørn T. May 5 '14 at 17:14
  • 2
    As for this particular case, I think you might have a gobble=4 set somewhere in your preamble, but without a complete example I can’t be sure. – alexwlchan May 5 '14 at 17:15
  • 2
    So @alexwlchan is right, you've added gobble=4 to the \lstset in the preamble. Also note that the M in MWE means 'minimal', and the code you posted isn't really that. You can read more about creating minimal working examples (MWE) at meta.tex.stackexchange.com/q/228 – Torbjørn T. May 5 '14 at 17:27
4

Your problem comes in this line from page_style:

gobble=4,

which is eating four spaces from the start of every line in your code blocks.

Quoting from the documentation for the listings package:

gobble=⟨number⟩

gobbles ⟨number⟩ characters at the beginning of each environment code line. This key has no effect on \lstinline or \lstinputlisting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.