I have the following LaTeX code:
\documentclass[11pt]{book}
\usepackage[default]{opensans}
\usepackage{alltt}
\usepackage[listings]{tcolorbox}
\usepackage{xcolor}
\newenvironment{generalSrcCode}
{\vspace{5pt}
\begin{tcolorbox}[
colback=lightgray,
coltext=black,
boxrule=0pt,
arc=5pt,
before skip=5pt,
after skip=5pt,
left=5pt,
right=5pt,
top=5pt,
bottom=5pt,
boxsep=0pt,
valign=center,
baseline = 0pt
]\begin{alltt}\color{black}\ignorespaces}
{\end{alltt}\end{tcolorbox}
\vspace{5pt}
}
\begin{document}
\noindent
Run the following commands in a terminal:
\begin{generalSrcCode}
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
\end{generalSrcCode}
\noindent
Once you have run the above-mentioned commands,
\end{document}
As you can see, there is a blank line at the end of the second command in the tcolorbox. I want to get rid of it and also center the content in the box vertically. Is this possible?
Thanks in advance
As you are anyway using a tcolorbox
around the code, I would directly use a tcblisting
:
\documentclass[11pt]{book}
\usepackage[default]{opensans}
\usepackage{alltt}
\usepackage[listings]{tcolorbox}
\usepackage{xcolor}
\NewTCBListing{generalSrcCode}{}{
colback=lightgray,
coltext=black,
boxrule=0pt,
arc=5pt,
before skip=5pt,
after skip=5pt,
left=5pt,
right=5pt,
top=5pt,
bottom=5pt,
boxsep=0pt,
valign=center,
baseline = 0pt,
listing only
}
\begin{document}
\noindent
Run the following commands in a terminal:
\begin{generalSrcCode}
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
\end{generalSrcCode}
\noindent
Once you have run the above-mentioned commands,
\end{document}