[Tex/LaTex] linebreak in tcolorbox

line-breakingtcolorbox

I'm new to LaTeX and am trying to get something like this in my document, i.e center aligning two lines inside a tcolorbox: this

However I cannot get this as \linebreak doesn't seem to work with tcolorbox.

What I end up with is something like this :

enter image description here

Here's my code :

\documentclass[a4paper]{article}

%% Language and font encodings
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}

%% Sets page size and margins
\usepackage[a4paper,top=3cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

%% Useful packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{multicol}
\usepackage{algpseudocode}
\usepackage{tcolorbox}

\title{MPI}


\begin{document}
\maketitle

\begin{tcolorbox}[colback = white]
\textbf{{\color{blue} MPI\_Init(int *argc, char **argv) }}
\begin{align}
Input : argc, argv arguments \linebreak
return : MPI\_SUCCESS or error code
\end{align}
\end{tcolorbox}

\end{document}

Will be great if someone could show how to do it correctly.

Thanks in advance.

Best Answer

I suggest to use a tabular environment in order to describe the C function arguments.

This is not really meant for listings or tcblistings, but the function header can be typeset with \lstinline.

\documentclass[a4paper]{article}

%% Language and font encodings
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}

%% Sets page size and margins
\usepackage[a4paper,top=3cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

%% Useful packages
\usepackage{amsmath}
%\usepackage{graphicx}
%\usepackage{wrapfig}
%\usepackage[colorinlistoftodos]{todonotes}
%\usepackage{multicol}
%\usepackage{algpseudocode}
\usepackage[most]{tcolorbox}
\usepackage{array}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}

\title{MPI}


\newcolumntype{D}{>{:}c}


\lstset{language={C}}

\newtcolorbox{MPIBox}[1][]{enhanced,sharp corners,colback = white,#1}


\begin{document}
\maketitle


\begin{MPIBox}
  {\bfseries \color{blue}
    \lstinline{MPI_Init(int *argc, char **argv)}
  }

  \begin{tabular}{@{\hskip2cm}p{2cm}Dp{5cm}}
    Input  &  & argc, argv arguments \tabularnewline
    return &  & MPI\_SUCCESS or error code
  \end{tabular}
\end{MPIBox}


\end{document}

enter image description here

Related Question