Tikz fancytitle 中的自动换行(换行)或手动换行

Tikz fancytitle 中的自动换行(换行)或手动换行

对于 Tikz Fancytitle,我该如何做:

  1. 获取自动换行,或
  2. 如果 1. 不可行,请添加手动换行符(例如,使用 \\)

我在这个例子中使用了嵌套的小页面,但问题也适用于外层小页面上的 Tikz 框上的标题!

谢谢!

电流输出:

在此处输入图片描述

梅威瑟:

\documentclass{article}
\usepackage[landscape]{geometry}
\usepackage{url}
\usepackage{multicol}
\usepackage{amsmath}
\usepackage{esint}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usepackage{amsmath,amssymb}

\usepackage{colortbl}
\usepackage{xcolor}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{enumitem}
\makeatletter
    
\usepackage[utf8]{inputenc}

\advance\topmargin-.8in
\advance\textheight3in
\advance\textwidth3in
\advance\paperheight1.5in 
\advance\oddsidemargin-1.5in
\advance\evensidemargin-1.5in
\parindent0pt
\parskip2pt
\newcommand{\hr}{\centerline{\rule{3.5in}{1pt}}}
    

\begin{document}

\begin{center}{\huge{\textbf{Notes}}}
\end{center}
\begin{multicols*}{3}

\tikzstyle{mybox} = [draw=black, fill=white, very thick,
    rectangle, rounded corners, inner sep=10pt, inner ysep=10pt]
\tikzstyle{fancytitle} =[fill=black, text=white, font=\bfseries]

%------------ Box1 ---------------
\begin{tikzpicture}
\node [mybox] (box){%
    \small
    \begin{minipage}{0.3\textwidth}
    
    %------------ Inner Box ---------------
    \begin{tikzpicture}
    \node [mybox] (box){%
        \small
        \begin{minipage}{0.3\textwidth}
        \end{minipage}
    };
    \node[fancytitle, right=10pt] at (box.north west) {This is a really long title.\With a second sentence. And another sentence. And one more.};
    \end{tikzpicture}
    
    \end{minipage}
};
\node[fancytitle, right=10pt] at (box.north west) {Box 1};
\end{tikzpicture}


\end{multicols*}
\end{document}

答案1

如果不在\href节点内使用这些宏,这将阻止换行,您可以将该align选项与手动换行一起使用,\\如下所示(我删除了不必要的包并优化了包的顺序):

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[landscape]{geometry}
\usepackage{multicol}
\usepackage{tikz}

\advance\topmargin-.8in
\advance\textheight3in
\advance\textwidth3in
\advance\paperheight1.5in 
\advance\oddsidemargin-1.5in
\advance\evensidemargin-1.5in
\parindent0pt
\parskip2pt

\usepackage{fourier}
\usepackage{hyperref}

\begin{document}

\begin{center}{\huge{\textbf{Notes}}}
\end{center}
\begin{multicols*}{3}

\tikzset{mybox/.style={draw=black, fill=white, very thick,
    rectangle, rounded corners, inner sep=10pt, inner ysep=10pt},
        fancytitle/.style={fill=black, text=white, font=\bfseries}
    }

%------------ Title ---------------
\begin{tikzpicture}
\node [mybox] (box){%
    \small
    \begin{minipage}{0.3\textwidth}
    
    %------------ Title ---------------
    \begin{tikzpicture}
    \node [mybox] (box){%
        \small
        \begin{minipage}{0.3\textwidth}
        \end{minipage}
    };
    \node[fancytitle, right=10pt, align=left] at (box.north west) {This is a really long title. With a second sentence. \\ And another sentence. And one more.};
    \end{tikzpicture}
    
    \end{minipage}
};
\node[fancytitle, right=10pt] at (box.north west) {Box 1};
\end{tikzpicture}

\end{multicols*}
\end{document}

在此处输入图片描述

您还可以使用选项text widthtext width=8cm例如)进行自动换行,但无论内部文本的长度如何,节点始终具有相同的宽度。

相关内容