我正在尝试创建自定义信息框(与awesomebox
包中的非常相似)。
一切模拟都很好,除非框周围没有文本。然后我收到一个错误There's no line here to end
。
我猜错误是因为\bigskip\newline
我的宏。我用它在环境和宏的顶部和底部创建了额外的填充
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=2cm]{geometry}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{fontawesome}
\parindent=0ex
\usepackage{xcolor}
% RED
\definecolor{redSeven}{rgb}{0.94, 0.24, 0.24}
\definecolor{redNine}{rgb}{0.79, 0.16, 0.16}
% ORANGE
\definecolor{orangeSeven}{rgb}{0.97, 0.4, 0.03}
\definecolor{orangeNine}{rgb}{0.85, 0.28, 0.06}
% BANS ----------------------------------------------------------------------
\newcommand{\banBox}[2][ban]{%
\bigskip\newline
\begin{minipage}{.1\textwidth}\centering
\textcolor{redSeven}{\fontsize{16}{24}\faicon{#1}}
\end{minipage}%
\textcolor{redSeven}{\vrule width 3pt \hspace{14pt}}
\begin{minipage}{.8\textwidth}
\textcolor{redNine}{#2}
\end{minipage}
\smallskip\newline
}
\newenvironment{banEnv}[1][ban]%
{\bigskip\newline%
\begin{minipage}{.1\textwidth}\centering%
\textcolor{redSeven}{\fontsize{16}{24}\faicon{#1}}%
\end{minipage}%
\textcolor{redSeven}{\vrule width 3pt \hspace{14pt}}%
\begin{minipage}{.8\textwidth}
\color{redNine}}
{\end{minipage}\bigskip\newline}
% WARNINGS ------------------------------------------------------------------
\newcommand{\warningBox}[2][exclamation-triangle]{%
\bigskip \newline
\begin{minipage}{.1\textwidth}\centering
\textcolor{orangeSeven}{\fontsize{16}{24}\faicon{#1}}
\end{minipage}%
\textcolor{orangeSeven}{\vrule width 3pt \hspace{14pt}}
\begin{minipage}{.8\textwidth}
\textcolor{orangeNine}{#2}
\end{minipage}
\newline
}
\newenvironment{warningEnv}[1][exclamation-triangle]%
{\bigskip\newline
\begin{minipage}{.1\textwidth}\centering%
\textcolor{orangeSeven}{\fontsize{16}{24}\faicon{#1}}%
\end{minipage}%
\textcolor{orangeSeven}{\vrule width 3pt \hspace{14pt}}%
\begin{minipage}{.8\textwidth}
\color{orangeNine}}
{\end{minipage}\bigskip\newline}
%-------------------------------------------------------------------------------
\begin{document}
Comment this line or Delete any commented line bellow
\banBox{Ban box.}
% A
\begin{banEnv}
Ban environment.\\
Lorem ipsum dolor sit amet.\\
Earum odit quia maiores nisi illum reiciendis aspernatur.
\end{banEnv}
% B
\warningBox{Warning box.}
% C
\begin{warningEnv}
Warning environment.\\
Lorem ipsum dolor sit amet\\
Earum odit quia maiores nisi illum reiciendis aspernatur.
\end{warningEnv}
% D
\end{document}
更新: 最糟糕的情况是两者之间没有界线。
\begin{document}
\banBox{Ban box.}
\begin{banEnv}
Ban environment.\\
Lorem ipsum dolor sit amet.\\
Earum odit quia maiores nisi illum reiciendis aspernatur.
\end{banEnv}
\warningBox{Warning box.}
\begin{warningEnv}
Warning environment.\\
Lorem ipsum dolor sit amet\\
Earum odit quia maiores nisi illum reiciendis aspernatur.
\end{warningEnv}
\end{document}
答案1
\bigskip\newline
我在命令前添加了一个空格字符\newline
。例如:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=2cm]{geometry}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{fontawesome}
\parindent=0ex
\usepackage{xcolor}
% RED
\definecolor{redSeven}{rgb}{0.94, 0.24, 0.24}
\definecolor{redNine}{rgb}{0.79, 0.16, 0.16}
% ORANGE
\definecolor{orangeSeven}{rgb}{0.97, 0.4, 0.03}
\definecolor{orangeNine}{rgb}{0.85, 0.28, 0.06}
% BANS ----------------------------------------------------------------------
\newcommand{\banBox}[2][ban]{%
\ \bigskip\newline % <----------------- added \ and space
\begin{minipage}{.1\textwidth}\centering
\textcolor{redSeven}{\fontsize{16}{24}\faicon{#1}}
\end{minipage}%
\textcolor{redSeven}{\vrule width 3pt \hspace{14pt}}
\begin{minipage}{.8\textwidth}
\textcolor{redNine}{#2}
\end{minipage}
\smallskip\newline
}
\newenvironment{banEnv}[1][ban]%
{\bigskip\newline%
\begin{minipage}{.1\textwidth}\centering%
\textcolor{redSeven}{\fontsize{16}{24}\faicon{#1}}%
\end{minipage}%
\textcolor{redSeven}{\vrule width 3pt \hspace{14pt}}%
\begin{minipage}{.8\textwidth}
\color{redNine}}
{\end{minipage}\bigskip\newline}
% WARNINGS ------------------------------------------------------------------
\newcommand{\warningBox}[2][exclamation-triangle]{%
\bigskip \newline
\begin{minipage}{.1\textwidth}\centering
\textcolor{orangeSeven}{\fontsize{16}{24}\faicon{#1}}
\end{minipage}%
\textcolor{orangeSeven}{\vrule width 3pt \hspace{14pt}}
\begin{minipage}{.8\textwidth}
\textcolor{orangeNine}{#2}
\end{minipage}
\newline
}
\newenvironment{warningEnv}[1][exclamation-triangle]%
{\bigskip\newline
\begin{minipage}{.1\textwidth}\centering%
\textcolor{orangeSeven}{\fontsize{16}{24}\faicon{#1}}%
\end{minipage}%
\textcolor{orangeSeven}{\vrule width 3pt \hspace{14pt}}%
\begin{minipage}{.8\textwidth}
\color{orangeNine}}
{\end{minipage}\bigskip\newline}
%-------------------------------------------------------------------------------
\begin{document}
%Comment this line or Delete any commented line bellow
\banBox{Ban box.}
A
\begin{banEnv}
Ban environment.\\
Lorem ipsum dolor sit amet.\\
Earum odit quia maiores nisi illum reiciendis aspernatur.
\end{banEnv}
B
\warningBox{Warning box.}
C
\begin{warningEnv}
Warning environment.\\
Lorem ipsum dolor sit amet\\
Earum odit quia maiores nisi illum reiciendis aspernatur.
\end{warningEnv}
D
\end{document}
附录:
如果我们删除 A、B、C 和 D 行,输出如下:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=2cm]{geometry}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{fontawesome}
\parindent=0ex
\usepackage{xcolor}
% RED
\definecolor{redSeven}{rgb}{0.94, 0.24, 0.24}
\definecolor{redNine}{rgb}{0.79, 0.16, 0.16}
% ORANGE
\definecolor{orangeSeven}{rgb}{0.97, 0.4, 0.03}
\definecolor{orangeNine}{rgb}{0.85, 0.28, 0.06}
% BANS ----------------------------------------------------------------------
\newcommand{\banBox}[2][ban]{%
\ \bigskip\newline
\begin{minipage}{.1\textwidth}\centering
\textcolor{redSeven}{\fontsize{16}{24}\faicon{#1}}
\end{minipage}%
\textcolor{redSeven}{\vrule width 3pt \hspace{14pt}}
\begin{minipage}{.8\textwidth}
\textcolor{redNine}{#2}
\end{minipage}
\smallskip\newline
}
\newenvironment{banEnv}[1][ban]%
{\ \bigskip\newline%
\begin{minipage}{.1\textwidth}\centering%
\textcolor{redSeven}{\fontsize{16}{24}\faicon{#1}}%
\end{minipage}%
\textcolor{redSeven}{\vrule width 3pt \hspace{14pt}}%
\begin{minipage}{.8\textwidth}
\color{redNine}}
{\end{minipage}\bigskip\newline}
% WARNINGS ------------------------------------------------------------------
\newcommand{\warningBox}[2][exclamation-triangle]{%
\ \bigskip \newline
\begin{minipage}{.1\textwidth}\centering
\textcolor{orangeSeven}{\fontsize{16}{24}\faicon{#1}}
\end{minipage}%
\textcolor{orangeSeven}{\vrule width 3pt \hspace{14pt}}
\begin{minipage}{.8\textwidth}
\textcolor{orangeNine}{#2}
\end{minipage}
\newline
}
\newenvironment{warningEnv}[1][exclamation-triangle]%
{\ \bigskip\newline
\begin{minipage}{.1\textwidth}\centering%
\textcolor{orangeSeven}{\fontsize{16}{24}\faicon{#1}}%
\end{minipage}%
\textcolor{orangeSeven}{\vrule width 3pt \hspace{14pt}}%
\begin{minipage}{.8\textwidth}
\color{orangeNine}}
{\end{minipage}\bigskip\newline}
%-------------------------------------------------------------------------------
\begin{document}
\banBox{Ban box.}
\begin{banEnv}
Ban environment.\\
Lorem ipsum dolor sit amet.\\
Earum odit quia maiores nisi illum reiciendis aspernatur.
\end{banEnv}
\warningBox{Warning box.}
\begin{warningEnv}
Warning environment.\\
Lorem ipsum dolor sit amet\\
Earum odit quia maiores nisi illum reiciendis aspernatur.
\end{warningEnv}
\end{document}