1

I want to have a line break in the text that I write inside a tikz table(example here A minimalist block in latex beamer). The latex code I have is:

\documentclass[10pt]{beamer}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{marvosym}
\usepackage{tcolorbox}
\usepackage{tikz}
\newcommand{\minimalisticBoxred}[2]{
\begin{figure}
\centering
\begin{tikzpicture}
\node(example-align)[red,rounded corners,draw,line width=1.5pt,inner sep=5ex](MBoxForm){#2};
\node[anchor=west,fill=white] at (MBoxForm.155) {#1};
\end{tikzpicture}
\end{figure}
}%\minimalisticBox{title}{contents} 
\begin{document}
\begin{frame}
\minimalisticBoxred{Tikz}{Example of text with a line break \\ Want to have a \\ line break here} 
\end{frame}
\end{document}

I followed few examples from this question's answers but it didn't work yet. What am I missing?

tachyon
  • 316

1 Answers1

1

Adding align=left to the first node I got

\documentclass[10pt]{beamer}
\usepackage{tikz}
\newcommand{\minimalisticBoxred}[2]{
\begin{figure}
\centering
\begin{tikzpicture}
\node(example-align)[red,rounded corners,draw,line width=1.5pt,inner
sep=5ex,align=left](MBoxForm){#2};
\node[anchor=west,fill=white] at (MBoxForm.155) {#1};
\end{tikzpicture}
\end{figure}
}%\minimalisticBox{title}{contents} 
\begin{document}
\begin{frame}
\minimalisticBoxred{Ti\emph{k}Z}{Example of text with a line break \\ Want to have a \\ line break here} 
\end{frame}
\end{document}

enter image description here

In general you need to specify an alignment or the text width to enable line breaks.

You were loading but not using tcolorbox in your code. Actually, I'd think that this might be better way to design the box.

tachyon
  • 316
  • Thanks, I am starting out with tikz so I missed the text width argument. Is there any way to keep the text in the box in default text colour and only change the outline of the table to red? – tachyon May 27 '20 at 21:02
  • 2
    @tachyon Sure. Instead of red,rounded corners,draw use draw=red,rounded corners or draw=red,rounded corners,text=black. (However, I still think you should consider using tcolorbox. The tikzpicture is fine, but you can't put another tikzpicture inside without nesting tikzpictures, and so on.) –  May 27 '20 at 21:04
  • 2
    The answer in tcolorbox is \begin{tcolorbox}[enhanced,attach boxed title to top left={xshift=5mm,yshift=-3mm,yshifttext=-1mm}, colback=white,colframe=red,colbacktitle=white,coltitle=black,title={Ti\emph{k}Z},halign=flush center,fonttitle=\bfseries, boxed title style={size=small,colframe=white}] Example of text with a line break \\ Want to have a \\ line break here \end{tcolorbox} – tachyon May 27 '20 at 21:20