继续阅读我的 xelatex 书,我无法解决如何将 tcblisting 置于中心。
这是我的(我希望这次),MWE:
% !TEX encoding = UTF-8
% !TEX program = xelatex
% !TEX spellcheck = es_ES
% !TEX root = draft.tex
\documentclass[a4]{article}
\usepackage{polyglossia}
\setmainlanguage{spanish}
\usepackage{lipsum}
\usepackage{libertine}
\usepackage{fontawesome}
\usepackage[most]{tcolorbox}
\definecolor{codebggray}{HTML}{ffffff}
\definecolor{codebordergray}{RGB}{200,200,200}
\usepackage[cache=false]{minted}
\BeforeBeginEnvironment{minted}{\begin{mdframed}[backgroundcolor=codebggray]}
\AfterEndEnvironment{minted}{\end{mdframed}}
% Tamaño y color del número de línea
\renewcommand{\theFancyVerbLine}{\ttfamily \textcolor[rgb]{0.4,0.4,0.4}{\large {\arabic{FancyVerbLine}}}}
\tcbuselibrary{listings,skins,xparse,hooks,many,minted}
\tcbset{
mysource/.style={
enhanced,
enlarge top initially by=5mm,
enlarge bottom finally by=5mm,
fonttitle=\bfseries,
sharp corners,
rounded corners=north,
center title,
box align=center, % <-- Tried to center this way (didn't work)
halign=center,
valign=center,
left=0pt,
right=0pt,
top=8pt,
bottom=8pt,
enlarge left by=0mm,
boxsep=5pt,
fontupper=\small,
arc=4pt,
outer arc=4pt,
leftupper=5mm,
width=0.9\linewidth,
title={#1},
overlay={%
\begin{tcbclipinterior}
\fill[gray!25] ([yshift=1pt]frame.south west) rectangle ([xshift=6mm]frame.north west);
\end{tcbclipinterior}
}
}
}
% Replace "sourcebox" with "psourcebox" in case you want to try the code
% that is commented below the following definition.
\newtcblisting{sourcebox}[1][]{
mysource={\color{black}#1},
listing engine=minted,
minted language=bash,
colback=codebggray,
colframe=codebordergray,
listing only,
breakable,
enhanced,
minted options = {
linenos,
breaklines=true,
breakbefore=.,
numbersep=2mm
},
overlay unbroken app = {%
\begin{tcbcliptitle}
\node[
anchor = north west,
inner ysep = 1.75mm,
inner xsep = 2mm
] at (frame.north west){\color{black}\Large\faCode};
\end{tcbcliptitle},
\node[anchor=north west,
minimum size=10pt,
draw=codebordergray,
fill=codebordergray] at ([xshift=-11pt,yshift=11pt]frame.south east)
{\ };
},
overlay first app = {%
\begin{tcbcliptitle}
\node[
anchor = north west,
inner ysep = 1.75mm,
inner xsep = 2mm
] at (frame.north west){\color{black}\Large\faCode};
\end{tcbcliptitle}
},
overlay last app = {%
\node[anchor=north west,
minimum size=10pt,
draw=codebordergray,
fill=codebordergray] at ([xshift=-11pt,yshift=11pt]frame.south east)
{\ };
}
}
% Tried to center with this, it gave me an error.
%\newenvironment{sourcebox}[1][]
%{\begin{figure}[h]\centering\begin{psourcebox}[#1]}
% {\end{psourcebox}\end{figure}}
\begin{document}
\lipsum[1]
\begin{sourcebox}[\texttt{while-do-done}]
#!/bin/bash
while [ "$OPCION" != 5 ]; do
echo " Listar archivos"
echo " Ver directorio de trabajo"
echo " Crear directorio"
echo " Crear usuario"
echo " Salir"
read -p "Ingrese una opción: " OPCION
case $OPCION in
1) ls;;
2) pwd;;
3) read -p "Nombre del directorio: " DIRECTORIO
mkdir $DIRECTORIO;;
4) if id | grep uid=0; then
read -p "Nombre del usuario: " NOMBREUSUARIO
useradd $NOMBREUSUARIO
else
echo "Se necesitan permisos de root"
fi
;;
5);;
*) echo "Opción ingresada invalida, intente de nuevo"
;;
esac
done
exit 0
\end{sourcebox}
\lipsum[2]
\end{document}
它看起来是这样的:
感谢您的帮助。