如何在标题后面添加矩形?

如何在标题后面添加矩形?

我有以下代码:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}

\title{\textbf{TITLE TITLE} \\ {\Large\itshape Subtitle}} % Title and subtitle

\author{Author} 
\date{February 2021}

\begin{document}

\makeatletter
\renewcommand{\maketitle}{ 
    \vspace*{20pt} % Vertical whitespace before the title
    \begin{flushright} % Right align
        {\LARGE\@title} % Increase the font size of the title
        
        \vspace{30pt} % Vertical whitespace between the title and author name
        
        {\large\@author}\\ % Author name
        \@date % Date
        
        \vspace{20pt} % Vertical whitespace between the author block and abstract
    \end{flushright}
}
\makeatother
\maketitle

\section{Introduction}

这会产生:

在此处输入图片描述

但我喜欢添加一个矩形作为标题的背景:在此处输入图片描述

或者甚至比这更花哨。我该怎么做?

谢谢。

答案1

借助该tcolorbox包,您可以实现类似的输出。根据文档的实际标题和副标题,您可能需要调整 的值text width

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}
\usepackage{tcolorbox}

\title{\textbf{TITLE TITLE} \\ {\Large\itshape Subtitle}} % Title and subtitle

\author{Author} 
\date{February 2021}

\definecolor{myorange}{RGB}{244,177,130}
\begin{document}

\makeatletter
\renewcommand{\maketitle}{
    \vspace*{20pt} % Vertical whitespace before the title
    \begin{flushright} % Right align 
      \begin{tcolorbox}[sharp corners,
                        rounded corners=northwest, 
                        rounded corners=southwest,
                        arc=5mm,
                        colback=myorange,
                        colframe=myorange,
                        text width=5cm]
        {\LARGE\@title} % Increase the font size of the title
       
        \vspace{30pt} % Vertical whitespace between the title and author name
        
        {\large\@author} % Author name
        
        \@date % Date
        
        \vspace{20pt} % Vertical whitespace between the author block and abstract

        \end{tcolorbox}
    \end{flushright}
}
\makeatother
\maketitle

\section{Introduction}

\end{document}

借助adjustboxfromchangepage包,橙色框可以拉伸到边缘:

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}
\usepackage{tcolorbox}
\usepackage{changepage}

\title{\textbf{TITLE TITLE} \\ {\Large\itshape Subtitle}} % Title and subtitle
\author{Author} 
\date{February 2021}
\definecolor{myorange}{RGB}{244,177,130}
\begin{document}

\makeatletter
\renewcommand{\maketitle}{
    \vspace*{20pt}
    \begin{adjustwidth}{}{-1in}
      \begin{flushright}
        \begin{tcolorbox}[sharp corners,
                        rounded corners=northwest, 
                        rounded corners=southwest,
                        arc=5mm,
                        colback=myorange,
                        colframe=myorange,
                        text width=\dimexpr4cm+1in]
          {\LARGE\@title}
       
          \vspace{30pt}
        
          {\large\@author}
        
          \@date
        
          \vspace{20pt}
        \end{tcolorbox}
      \end{flushright}
    \end{adjustwidth}
}
\makeatother
\maketitle

\section{Introduction}

\end{document}

相关内容