Is there the posibility to use the initial line numbering from the code I want to list in my latex file? So the code should be numbered like in the picture:
But using the following code, the numbering starts from 1
\lstinputlisting[language=C,
numbers=left,
numberfirstline=false,
keywordstyle=\color{blue},
commentstyle=\color{green},
stringstyle=\color{red},
firstline=222, lastline=228]{Test_Fehlerbehebung_LIN.can}
And why is the first number (1) obove the first row? Shouldn't numberfirstline=false fix this problem?
This ist the minimal example:
\documentclass[]{scrreprt}
\usepackage{colortbl}
\usepackage{listings}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
%backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{black},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2,
firstnumber=auto
}
\begin{document}
\lstset{basicstyle=\footnotesize, style=mystyle}
\lstinputlisting[language=C]{Code/Test_Fehlerbehebung_LIN.c}
\end{document}
You can use the same fix as in https://tex.stackexchange.com/a/27240/36296
\documentclass[]{scrreprt}
\usepackage{colortbl}
\usepackage{listings}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
numbers=left,
}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\lst#GLI#}% <command>
{\def\lst#firstline{#1\relax}}% <search>
{\def\lst#firstline{#1\relax}\def\lst#firstnumber{#1\relax}}% <replace>
{\typeout{listings firstnumber=firstline}}% <success>
{\typeout{listings firstnumber not set}}% <failure>
\makeatother
\begin{document}
\lstset{basicstyle=\footnotesize, style=mystyle}
\lstinputlisting[language=C,firstline=10, lastline=20,firstnumber=firstline]{document.tex}
\end{document}
Related
There is a lot of space in the beginning which I do no like. And also to other sections (but only the start page of the section). Do you guys have any clue on how to reduce the vertical space between the header and the actual content.
\documentclass[12pt, a4paper, oneside, openany]{scrbook}
\pagestyle{headings}
%page layout
\setlength{\voffset}{0mm}
\setlength{\topmargin}{0mm}
\setlength{\headsep}{0mm}
\setlength{\oddsidemargin}{0mm}
\setlength{\evensidemargin}{0mm}
\setlength{\textheight}{210mm}
\setlength{\textwidth}{150mm}
\setlength{\marginparwidth}{5mm}
\setlength{\marginparsep}{3mm}
\setlength{\marginparpush}{7mm}
\setlength{\parindent}{5mm}
\setlength{\footskip}{0mm}
\usepackage{fontspec}
\fontspec{Times New Roman}
\usepackage{url}
\linespread{1.5}
\usepackage[acronym]{glossaries}
\parindent 10mm
\parskip 5mm
\usepackage{graphicx}
\graphicspath{{images/}}
\usepackage[a4paper]{geometry}
You can redeclare the sectioning command which you'd like to change and set whatever beforeskip you like:
% !TeX TS-program = lualatex
\documentclass[12pt, a4paper, oneside, openany]{scrbook}
\pagestyle{headings}
\RedeclareSectionCommand[beforeskip=0pt]{chapter}
%page layout
\setlength{\voffset}{0mm}
\setlength{\topmargin}{0mm}
\setlength{\headsep}{0mm}
\setlength{\oddsidemargin}{0mm}
\setlength{\evensidemargin}{0mm}
\setlength{\textheight}{210mm}
\setlength{\textwidth}{150mm}
\setlength{\marginparwidth}{5mm}
\setlength{\marginparsep}{3mm}
\setlength{\marginparpush}{7mm}
\setlength{\parindent}{5mm}
\setlength{\footskip}{0mm}
\usepackage{fontspec}
\fontspec{Times New Roman}
\usepackage{url}
\linespread{1.5}
\usepackage[acronym]{glossaries}
\parindent 10mm
\parskip 5mm
\usepackage{graphicx}
\graphicspath{{images/}}
\usepackage[a4paper]{geometry}
\begin{document}
\chapter{title}
\end{document}
Answer courtesy of https://tex.stackexchange.com/questions/62125/how-to-remove-top-margin-above-tableofcontents. Visit this excellent post to get a comprehensive explanation and alternative methods to do your stuff.
Add the following to your preamble:
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{\begingroup%
\patchcmd{\#makeschapterhead}% <cmd>
{\vspace*{50\p#}}% <search>
{}% <replace>
{}{}% <success><failure>
\oldtableofcontents%
\endgroup%
}
\makeatother
The above does a local search-and-replace within #makeschapterhead (replacing \vspace*{50\p#} with nothing, before calling the regular table of contents. The redefinition (search-and-replace) is localized within the scope of the group.
I got a new PC with Windows 10 Pro operating system several days ago and decided to install TeXstudio + MiKTeX.
And I faced a problem compiling LaTeX file. The problem is when I try to add \usepackage{hyperref} or code stuff similar to this line (more detailed in the code with the comment line % problem is here if I add this line) I get an error which says: Argument of � has an extra }. \end{document}.
My code:
\documentclass[10pt,a4paper]{report}
\usepackage{cmap}
\usepackage{setspace}
\onehalfspacing
\usepackage{multicol}
\usepackage{textcomp}
\usepackage{verbatim}
\usepackage{floatrow,calc}
\DeclareFloatSeparators{mysep}{\hspace{3cm}}
\thisfloatsetup{floatrowsep=mysep}
\usepackage{ucs}
\usepackage[pdftex]{graphicx}
\usepackage{epstopdf}
\usepackage{amssymb,amsmath}
\DeclareGraphicsExtensions{.pdf, .png, .jpg}
\usepackage[labelsep=period]{caption}
\usepackage[utf8x]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[russian, english]{babel}
\usepackage[left=3cm, right=1.5cm, top=1.5cm, bottom=2cm]{geometry}
\usepackage{indentfirst}
\usepackage{color}
\definecolor{Black}{rgb}{0,0,0}
\usepackage[unicode, colorlinks, linkcolor=Black]{hyperref} % problem is here if I add this line
\usepackage{xcolor}
\definecolor{linkcolor}{HTML}{000000}
\definecolor{urlcolor}{HTML}{000000}
\hypersetup{pdfstartview=FitH, linkcolor=linkcolor, urlcolor=urlcolor, colorlinks=True} % problem is here if I add this line
\fontfamily{ptm}
\parindent=1cm
\sloppy
\bibliographystyle{unsrt}
\usepackage{hyperref} % problem is here if I add this line
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead{\leftmark}
\cfoot{\thepage}
\renewcommand{\headrulewidth}{1pt}
\usepackage{subfig}
\usepackage{epigraph} %%% to make inspirational quotes.
\usepackage{amsfonts}
\begin{document}
Random text
${\mathcal {E}}=-{{d\Phi_{B}} \over dt},$ where
${\mathcal {E}}$ — random letter.
\end{document}
Error I get:
Error
When I try this code in OverLeaf or on my notebook or without hyperref packages - everything's fine. But I need this package if, for example, I'll have to add references...
Did someone face similar problem? Maybe I need to install some other packages?
A quote from the hyperref maintainer:
But I would recommend to drop utf8x/ucs. Most improvements in the handling of utf8 which e.g. allow you to use them in \labels and filenames are undone by utf8x/ucs.
If the ucs package and utf8x inputenc option is removed, your code compiles.
Furthermore you should remove the pdftex from graphicx. It will automatically choose the best suited option to match your compilation chain.
You should also not load the same package multiple times, in particular not with different options
And load hyperref after the other packages (there are only very view exceptions)
No need to load color if you also load xcolor
\documentclass[10pt,a4paper]{report}
\usepackage{cmap}
\usepackage{setspace}
\onehalfspacing
\usepackage{multicol}
\usepackage{textcomp}
\usepackage{verbatim}
\usepackage{floatrow,calc}
\DeclareFloatSeparators{mysep}{\hspace{3cm}}
\thisfloatsetup{floatrowsep=mysep}
%\usepackage{ucs}
\usepackage[
%pdftex
]{graphicx}
\usepackage{epstopdf}
\usepackage{amssymb,amsmath}
\DeclareGraphicsExtensions{.pdf, .png, .jpg}
\usepackage[labelsep=period]{caption}
%\usepackage[utf8x]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[russian, english]{babel}
\usepackage[left=3cm, right=1.5cm, top=1.5cm, bottom=2cm]{geometry}
\usepackage{indentfirst}
\usepackage{xcolor}
\definecolor{Black}{rgb}{0,0,0}
\fontfamily{ptm}
\parindent=1cm
\sloppy
\bibliographystyle{unsrt}
%\usepackage{hyperref} % problem is here if I add this line
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead{\leftmark}
\cfoot{\thepage}
\renewcommand{\headrulewidth}{1pt}
\usepackage{subfig}
\usepackage{epigraph} %%% to make inspirational quotes.
\usepackage{amsfonts}
%\usepackage{xcolor}
\usepackage[unicode, colorlinks, linkcolor=Black]{hyperref} % problem is here if I add this line
\definecolor{linkcolor}{HTML}{000000}
\definecolor{urlcolor}{HTML}{000000}
\hypersetup{pdfstartview=FitH, linkcolor=linkcolor, urlcolor=urlcolor, colorlinks=True} % problem is here if I add this line
\begin{document}
Random text
${\mathcal {E}}=-\frac{{d\Phi_{B}} }{ dt},$ where
${\mathcal {E}}$ — random letter.
\end{document}
I got a new PC with Windows 10 Pro operating system several days ago and decided to install TeXstudio + MiKTeX.
And I faced a problem compiling LaTeX file. The problem is when I try to add \usepackage{hyperref} or code stuff similar to this line (more detailed in the code with the comment line % problem is here if I add this line) I get an error which says: Argument of � has an extra }. \end{document}.
My code:
\documentclass[10pt,a4paper]{report}
\usepackage{cmap}
\usepackage{setspace}
\onehalfspacing
\usepackage{multicol}
\usepackage{textcomp}
\usepackage{verbatim}
\usepackage{floatrow,calc}
\DeclareFloatSeparators{mysep}{\hspace{3cm}}
\thisfloatsetup{floatrowsep=mysep}
\usepackage{ucs}
\usepackage[pdftex]{graphicx}
\usepackage{epstopdf}
\usepackage{amssymb,amsmath}
\DeclareGraphicsExtensions{.pdf, .png, .jpg}
\usepackage[labelsep=period]{caption}
\usepackage[utf8x]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[russian, english]{babel}
\usepackage[left=3cm, right=1.5cm, top=1.5cm, bottom=2cm]{geometry}
\usepackage{indentfirst}
\usepackage{color}
\definecolor{Black}{rgb}{0,0,0}
\usepackage[unicode, colorlinks, linkcolor=Black]{hyperref} % problem is here if I add this line
\usepackage{xcolor}
\definecolor{linkcolor}{HTML}{000000}
\definecolor{urlcolor}{HTML}{000000}
\hypersetup{pdfstartview=FitH, linkcolor=linkcolor, urlcolor=urlcolor, colorlinks=True} % problem is here if I add this line
\fontfamily{ptm}
\parindent=1cm
\sloppy
\bibliographystyle{unsrt}
\usepackage{hyperref} % problem is here if I add this line
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead{\leftmark}
\cfoot{\thepage}
\renewcommand{\headrulewidth}{1pt}
\usepackage{subfig}
\usepackage{epigraph} %%% to make inspirational quotes.
\usepackage{amsfonts}
\begin{document}
Random text
${\mathcal {E}}=-{{d\Phi_{B}} \over dt},$ where
${\mathcal {E}}$ — random letter.
\end{document}
Error I get:
Error
When I try this code in OverLeaf or on my notebook or without hyperref packages - everything's fine. But I need this package if, for example, I'll have to add references...
Did someone face similar problem? Maybe I need to install some other packages?
A quote from the hyperref maintainer:
But I would recommend to drop utf8x/ucs. Most improvements in the handling of utf8 which e.g. allow you to use them in \labels and filenames are undone by utf8x/ucs.
If the ucs package and utf8x inputenc option is removed, your code compiles.
Furthermore you should remove the pdftex from graphicx. It will automatically choose the best suited option to match your compilation chain.
You should also not load the same package multiple times, in particular not with different options
And load hyperref after the other packages (there are only very view exceptions)
No need to load color if you also load xcolor
\documentclass[10pt,a4paper]{report}
\usepackage{cmap}
\usepackage{setspace}
\onehalfspacing
\usepackage{multicol}
\usepackage{textcomp}
\usepackage{verbatim}
\usepackage{floatrow,calc}
\DeclareFloatSeparators{mysep}{\hspace{3cm}}
\thisfloatsetup{floatrowsep=mysep}
%\usepackage{ucs}
\usepackage[
%pdftex
]{graphicx}
\usepackage{epstopdf}
\usepackage{amssymb,amsmath}
\DeclareGraphicsExtensions{.pdf, .png, .jpg}
\usepackage[labelsep=period]{caption}
%\usepackage[utf8x]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[russian, english]{babel}
\usepackage[left=3cm, right=1.5cm, top=1.5cm, bottom=2cm]{geometry}
\usepackage{indentfirst}
\usepackage{xcolor}
\definecolor{Black}{rgb}{0,0,0}
\fontfamily{ptm}
\parindent=1cm
\sloppy
\bibliographystyle{unsrt}
%\usepackage{hyperref} % problem is here if I add this line
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead{\leftmark}
\cfoot{\thepage}
\renewcommand{\headrulewidth}{1pt}
\usepackage{subfig}
\usepackage{epigraph} %%% to make inspirational quotes.
\usepackage{amsfonts}
%\usepackage{xcolor}
\usepackage[unicode, colorlinks, linkcolor=Black]{hyperref} % problem is here if I add this line
\definecolor{linkcolor}{HTML}{000000}
\definecolor{urlcolor}{HTML}{000000}
\hypersetup{pdfstartview=FitH, linkcolor=linkcolor, urlcolor=urlcolor, colorlinks=True} % problem is here if I add this line
\begin{document}
Random text
${\mathcal {E}}=-\frac{{d\Phi_{B}} }{ dt},$ where
${\mathcal {E}}$ — random letter.
\end{document}
I got a new PC with Windows 10 Pro operating system several days ago and decided to install TeXstudio + MiKTeX.
And I faced a problem compiling LaTeX file. The problem is when I try to add \usepackage{hyperref} or code stuff similar to this line (more detailed in the code with the comment line % problem is here if I add this line) I get an error which says: Argument of � has an extra }. \end{document}.
My code:
\documentclass[10pt,a4paper]{report}
\usepackage{cmap}
\usepackage{setspace}
\onehalfspacing
\usepackage{multicol}
\usepackage{textcomp}
\usepackage{verbatim}
\usepackage{floatrow,calc}
\DeclareFloatSeparators{mysep}{\hspace{3cm}}
\thisfloatsetup{floatrowsep=mysep}
\usepackage{ucs}
\usepackage[pdftex]{graphicx}
\usepackage{epstopdf}
\usepackage{amssymb,amsmath}
\DeclareGraphicsExtensions{.pdf, .png, .jpg}
\usepackage[labelsep=period]{caption}
\usepackage[utf8x]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[russian, english]{babel}
\usepackage[left=3cm, right=1.5cm, top=1.5cm, bottom=2cm]{geometry}
\usepackage{indentfirst}
\usepackage{color}
\definecolor{Black}{rgb}{0,0,0}
\usepackage[unicode, colorlinks, linkcolor=Black]{hyperref} % problem is here if I add this line
\usepackage{xcolor}
\definecolor{linkcolor}{HTML}{000000}
\definecolor{urlcolor}{HTML}{000000}
\hypersetup{pdfstartview=FitH, linkcolor=linkcolor, urlcolor=urlcolor, colorlinks=True} % problem is here if I add this line
\fontfamily{ptm}
\parindent=1cm
\sloppy
\bibliographystyle{unsrt}
\usepackage{hyperref} % problem is here if I add this line
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead{\leftmark}
\cfoot{\thepage}
\renewcommand{\headrulewidth}{1pt}
\usepackage{subfig}
\usepackage{epigraph} %%% to make inspirational quotes.
\usepackage{amsfonts}
\begin{document}
Random text
${\mathcal {E}}=-{{d\Phi_{B}} \over dt},$ where
${\mathcal {E}}$ — random letter.
\end{document}
Error I get:
Error
When I try this code in OverLeaf or on my notebook or without hyperref packages - everything's fine. But I need this package if, for example, I'll have to add references...
Did someone face similar problem? Maybe I need to install some other packages?
A quote from the hyperref maintainer:
But I would recommend to drop utf8x/ucs. Most improvements in the handling of utf8 which e.g. allow you to use them in \labels and filenames are undone by utf8x/ucs.
If the ucs package and utf8x inputenc option is removed, your code compiles.
Furthermore you should remove the pdftex from graphicx. It will automatically choose the best suited option to match your compilation chain.
You should also not load the same package multiple times, in particular not with different options
And load hyperref after the other packages (there are only very view exceptions)
No need to load color if you also load xcolor
\documentclass[10pt,a4paper]{report}
\usepackage{cmap}
\usepackage{setspace}
\onehalfspacing
\usepackage{multicol}
\usepackage{textcomp}
\usepackage{verbatim}
\usepackage{floatrow,calc}
\DeclareFloatSeparators{mysep}{\hspace{3cm}}
\thisfloatsetup{floatrowsep=mysep}
%\usepackage{ucs}
\usepackage[
%pdftex
]{graphicx}
\usepackage{epstopdf}
\usepackage{amssymb,amsmath}
\DeclareGraphicsExtensions{.pdf, .png, .jpg}
\usepackage[labelsep=period]{caption}
%\usepackage[utf8x]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[russian, english]{babel}
\usepackage[left=3cm, right=1.5cm, top=1.5cm, bottom=2cm]{geometry}
\usepackage{indentfirst}
\usepackage{xcolor}
\definecolor{Black}{rgb}{0,0,0}
\fontfamily{ptm}
\parindent=1cm
\sloppy
\bibliographystyle{unsrt}
%\usepackage{hyperref} % problem is here if I add this line
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead{\leftmark}
\cfoot{\thepage}
\renewcommand{\headrulewidth}{1pt}
\usepackage{subfig}
\usepackage{epigraph} %%% to make inspirational quotes.
\usepackage{amsfonts}
%\usepackage{xcolor}
\usepackage[unicode, colorlinks, linkcolor=Black]{hyperref} % problem is here if I add this line
\definecolor{linkcolor}{HTML}{000000}
\definecolor{urlcolor}{HTML}{000000}
\hypersetup{pdfstartview=FitH, linkcolor=linkcolor, urlcolor=urlcolor, colorlinks=True} % problem is here if I add this line
\begin{document}
Random text
${\mathcal {E}}=-\frac{{d\Phi_{B}} }{ dt},$ where
${\mathcal {E}}$ — random letter.
\end{document}
Im getting a warning, as in tittle. Because of that (I think so) I cant see specified bacground colors and so on. Below I paste the source code.
The error tells that it do not recognize the "true - how can I fix that?
\documentclass[final,3p,times]{elsarticle}
\pgfplotsset{compat=1.18}
\begin{document}
\textbf{Appendix: moving mesh}
\lstinputlisting[language=python, captionpos=t, label={ListingRecHEL1}]{data/code.py}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.6,0.9,0.1}
\renewcommand{\lstlistingname}{Kod}% Listing -> Algorithm
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{codepurple},
numberstyle=\tiny\color{codegray},
stringstyle=\color{orange},
basicstyle=\ttfamily\tiny,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
name = "Kod"
}
\lstset{style=mystyle}
\clearpage
\end{document}
I have no clue what this documentclass is, so I used a KOMA class. Should have no effect on lstlisting.
And mentioned in the comments, your example is not a working MWE, it is messed up with code that is not helpful to solve your issue.
The trick is simple: Just read the compilers messages. When it tells you, that there is an unknown option, you should try to remove it and compile again. numbers=true is not valid and not needed.
Doc of listings
A working example that may come close to yours:
\documentclass[]{scrartcl}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{hyperref}
\begin{document}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.6,0.9,0.1}
\renewcommand{\lstlistingname}{Kod}% Listing -> Algorithm
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{codepurple},
numberstyle=\tiny\color{codegray},
stringstyle=\color{orange},
basicstyle=\ttfamily\tiny,
breakatwhitespace=false
commentstyle=\color{codegreen},
keywordstyle=\color{codepurple},
numberstyle=\tiny\color{codegray},
stringstyle=\color{orange},
basicstyle=\ttfamily\tiny,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
%numbers=true % <-----your tex compiler tells you that it is unknown
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2,
name = "Kod"
}
\lstinputlisting[
language=python,
style=mystyle,
captionpos=t,
caption={My Python program},
label={lst:promise}
]{code.py}
In \autoref{lst:promise} I did my very best.
\end{document}
The code.py:
def main():
"""This is a function"""
return 'I will provide MWE when asking LaTeX related questions.'
# and this a line comment
if __name__=='__main__':
print(main())
The result: