1

please, how should I set frame of listlings like line not line at bottom and dash on sides. Thank you

\documentclass[12pt,a4paper]{report}
\usepackage[left=2cm,right=2cm,top=2.5cm,bottom=2.5cm]{geometry}

\usepackage[a-2u]{pdfx}

\usepackage[czech]{babel}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{%
  \parbox{\textwidth}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}\vskip-4pt}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
\lstset{frame=lrb,xleftmargin=\fboxsep,xrightmargin=-\fboxsep}

\renewcommand{\lstlistingname}{Soubor}

\newcommand{\listingsfont}{\ttfamily}

\begin{document}

\lstinputlisting[caption=\textbf{Vstupní soubor \texttt{.SPD} programu SPEL (pro první čáru)}, label=c_1, basicstyle=\footnotesize\linespread{0.2}\listingsfont]{spd.txt}

\end{document}

I am grateful for @BambOo 's help and his code. Now I have a problem with compilation of this code. There is maybe a problem with packages - everyshi.sty is missing. I didn't find it in MiKTex Console. I use TexMaker. Thank you very much.

\documentclass[12pt,a4paper]{article}
\usepackage[left=2cm,right=2cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{caption}


\renewcommand{\lstlistingname}{Soubor}

\newcommand{\listingsfont}{\ttfamily}

\usepackage{tcolorbox}
\tcbuselibrary{listings}
\newtcbinputlisting[]{\mylisting}[2][]{listing file={#2},title=Listing,colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,listing only,#1}


\begin{document}

\mylisting[]{spd.txt}

\end{document}

enter image description here

enter image description here

1

If you want a fine definition of the listings graphical options, you can use the nice tcolorbox package which has a listings library defining the \newtcbinputlisting macro, have a look at the tcolorbox documentation at page 298 Section 15.

\documentclass[12pt,a4paper]{article}
\usepackage[left=2cm,right=2cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{%
  \parbox{\textwidth}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}\vskip-4pt}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
\lstset{xleftmargin=\fboxsep,xrightmargin=-\fboxsep}

\renewcommand{\lstlistingname}{Soubor}

\newcommand{\listingsfont}{\ttfamily}

\usepackage{tcolorbox}
\tcbuselibrary{listings}
\newtcbinputlisting[]{\mylisting}[2][]{listing file={#2},title=Listing,colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,listing only,#1}

\begin{filecontents*}{spd.txt}
HJD-2400000         RV                  weight ...
55836.5692          -13.1464            1.00   ...
\end{filecontents*}

\begin{document}

\lstinputlisting[caption=\textbf{Vstupní soubor \texttt{.SPD} programu SPEL (pro první čáru)}, label=c_1, basicstyle=\footnotesize\linespread{0.2}\listingsfont]{spd.txt}

\mylisting[]{spd.txt}

\end{document}

EDIT To authorize the breaking of the listing, add \tcbuselibrary{breakable} to your preamble after \usepackage{tcolorbox} then add breakable in \newtcbinputlisting[]{\mylisting}[2][]{...

EDIT Final version including breakable and the caption definition.

\documentclass[12pt,a4paper]{article}
\usepackage[left=2cm,right=2cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{%
  \parbox{\textwidth}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}\vskip-4pt}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
\lstset{xleftmargin=\fboxsep,xrightmargin=-\fboxsep}

\renewcommand{\lstlistingname}{Soubor}

\newcommand{\listingsfont}{\ttfamily}

\usepackage{tcolorbox}
\tcbuselibrary{listings}
\tcbuselibrary{breakable}
\newtcbinputlisting[auto counter] % <-- to activate the counter
{\mylisting}[2][]{
listing file={#2}, % <-- argument in {} of \mylisting is the filename
title=Listing,colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,listing only,
breakable, % <-- table can span multiple pages
title={Soubor \thetcbcounter: #1}} % <-- argument in [] of \mylisting is the title with counter

\begin{filecontents*}{spd.txt}
HJD-2400000         RV                  weight ...
55836.5692          -13.1464            1.00   ...
\end{filecontents*}

\begin{document}

\mylisting[SPD]{spd.txt}

\end{document}

enter image description here

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.