如果不为空则显示 \subtitle

如果不为空则显示 \subtitle

如果已定义字幕,如何显示它?

有字幕的时候代码如下:

\begin{center}
 \MakeTextUppercase{\textbf{\thetitle:}}\\
 \MakeTextUppercase{\thesubtitle}
\{center}

如果没有字幕的话,则是这样的:

\begin{center}
 \MakeTextUppercase{\textbf{\thetitle}}
\{center}

在此处输入图片描述

编辑

这是main.tex

\documentclass{abntex2}

%% This is how the Class abntex2 create the command '\titulo' for the title
%\newcommand{\titulo}[1]{\title{#1}}
%\newcommand{\imprimirtitulo}{\thetitle}
% ---
%% This is how I created the command '\subtitulo' for the subtitle
\providecommand{\imprimirsubtitulo}{} % means 'print subtitle'
\newcommand{\subtitulo}[1]{\renewcommand{\imprimirsubtitulo}{#1}}
% ---
% Changing the cover page
\renewcommand{\imprimircapa}{% means 'print cover page'
    \begin{capa}%
        \center

        \vspace*{3,5cm}

        \MakeTextUppercase{\textbf{\imprimirinstituicao}}

        \vspace*{2cm}

        \MakeTextUppercase{\textbf{\imprimirautor}}

        \vspace*{3cm}
        \begin{center}
        \MakeTextUppercase{\textbf{\imprimirtitulo:}}\\
        \MakeTextUppercase{\imprimirsubtitulo{}}
        \end{center}
        \vfill

        \MakeTextUppercase{\textbf{\imprimirlocal}}

        \textbf{\imprimirdata}
    \end{capa}
}
% ---

\titulo{The title}
\subtitulo{subtitle}
\autor{Author}
\local{Local}
\data{2015}
\instituicao{Institution}

\begin{document}

\imprimircapa

\end{document}

注意:我是巴西人,我上的课是葡萄牙语的。

答案1

由于您自己定义了副标题宏和标题位置,因此有很多选择。例如,您还可以定义\if-条件,例如\ifsubtitle,和相应的条件。即

\ifsubtitle
  <true clause>
\else
  <false clause>
\fi

就您而言,可以将\else( <false clause>) 留空。

\documentclass{abntex2}

%% This is how the Class abntex2 create the command '\titulo' for the title
%\newcommand{\titulo}[1]{\title{#1}}
%\newcommand{\imprimirtitulo}{\thetitle}
% ---
%% This is how I created the command '\subtitulo' for the subtitle
\providecommand{\imprimirsubtitulo}{} % means 'print subtitle'
\newif\ifsubtitle% Default is \subtitlefalse
\newcommand{\subtitulo}[1]{%
  \renewcommand{\imprimirsubtitulo}{#1}%
  \global\subtitletrue}
% ---
% Changing the cover page
\renewcommand{\imprimircapa}{% means 'print cover page'
  \begin{capa}%
    \centering

    \vspace*{3.5cm}

    \MakeTextUppercase{\textbf{\imprimirinstituicao}}

    \vspace*{2cm}

    \MakeTextUppercase{\textbf{\imprimirautor}}

    \vspace*{3cm}

    \MakeTextUppercase{\textbf{\imprimirtitulo}}%
    \ifsubtitle
      \textbf{:}\\
      \MakeTextUppercase{\imprimirsubtitulo{}}
    \fi

    \vfill

    \MakeTextUppercase{\textbf{\imprimirlocal}}

    \textbf{\imprimirdata}
  \end{capa}
}
% ---

\titulo{The title}
\subtitulo{subtitle}
\autor{Author}
\local{Local}
\data{2015}
\instituicao{Institution}

\begin{document}

\imprimircapa

\end{document}

\imprimircapa我也对宏做了一些细微的改变。

相关内容