我正在尝试使用嵌套的左括号编写某种方案,但代码编译时会抛出错误,我猜我没有关闭括号(我不希望它们关闭,只需要左括号)所以编译器会报错。我该如何解决这个问题?提前非常感谢。
\documentclass[11pt, tikz]{article}
\usepackage{answers}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{slashbox}
\usepackage{enumitem}
\usepackage[colorlinks]{hyperref}
\usepackage{multicol}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{mathrsfs}
\usepackage[table,x11names]{xcolor}
\usepackage[margin=1in]{geometry}
\usepackage{float}
\usepackage{amsmath,amsthm,amssymb}
\usepackage[utf8]{inputenc}
\usepackage {tikz}
\usepackage{multicol}
\usetikzlibrary{trees}
\usepackage{tikz-timing}[2014/10/29]
\usetikztiminglibrary[rising arrows]{clockarrows}
\usetikzlibrary {positioning}
\usepackage{xcolor}
\definecolor {processblue}{cmyk}{0.96,0,0,0}
\usepackage{caption}
\usepackage{array}
\newcolumntype{?}{!{\vrule width 2pt}}
\usepackage[spanish, es-tabla]{babel}
\makeatletter
\renewcommand{\@seccntformat}[1]{}
\makeatother
\setlength\parindent{24pt}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\begin{document}
\[\text{Temperature}=\left\{
\begin{array}{ll}
\text{Hot} &
\[\left\{
\begin{array}{ll}
\text{No: 2} & \\
\text{Yes: 2} & \\
\end{array} \\
\text{Mild} &
\[\left\{
\begin{array}{ll}
\text{No: 2} & \\
\text{Yes: 4} & \\
\end{array} \\
\text{Cool} &
\[\left\{
\begin{array}{ll}
\text{No: 1} & \\
\text{Yes: 3} & \\
\end{array} \\
\end{array}
\right. \]
\end{document}
答案1
我认为,嵌套环境更简单 cases
。以下是可能的代码,并进行了一些布局改进:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\text{Temperature} = \begin{cases}
\text{Hot} &
\begin{cases}
\text{No:} & 2\\
\text{Yes:} & 2
\end{cases} \\[2.5ex]
\text{Mild} &
\begin{cases}
\text{No:} & 2 \\
\text{Yes:} & 4
\end{cases}\\[2.5ex]
\text{Cool} &
\begin{cases}
\text{No:} & 1\\
\text{Yes:} & 3
\end{cases} %\\
\end{cases}
\]
\end{document}
答案2
正确。您必须用同一组中的\left
随附 - 括号关闭每个打开的 - 括号。此处的“括号”包括可扩展括号,如、、、和以及空分隔符。\right
(
)
[
]
\{
\}
.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\text{Temperature} = \left\{\begin{array}{ll}
\text{Hot} &
\left\{\begin{array}{ll}
\text{No: 2} & \\
\text{Yes: 2} & \\
\end{array}\right. \\
\text{Mild} &
\left\{\begin{array}{ll}
\text{No: 2} & \\
\text{Yes: 4} & \\
\end{array}\right. \\
\text{Cool} &
\left\{\begin{array}{ll}
\text{No: 1} & \\
\text{Yes: 3} & \\
\end{array}\right. \\
\end{array}\right.
\]
\end{document}
答案3
你不应该\[
一遍又一遍地开始。
我在这里提供了一个语法更简单的代码,但定义却不那么简单。
\documentclass[11pt]{article}
\usepackage{amsmath,booktabs}
\newif\ifbtextinmath
\newenvironment{btext}[1]
{% the conditional is initially false
\btextinmathfalse
% if btext is initiated in math mode, make the conditional true
% otherwise start math mode
\ifmmode\btextinmathtrue\else$\fi
% left brace
\left\{
% start a tabular
\begin{tabular}{#1}%
}
{% end the tabular
\end{tabular}%
% null delimiter
\right.%
% if the conditional is true, do nothing; otherwise end math mode
\ifbtextinmath\else$\fi
}
\begin{document}
\[
\text{Temperature}=
\begin{btext}{@{}l@{\ }l@{}}
Hot &
\begin{btext}{@{}l@{\ }l@{}}
No: & 2 \\
Yes: & 2
\end{btext} \\
\addlinespace
Mild &
\begin{btext}{@{}l@{\ }l@{}}
No: & 2 \\
Yes: & 4
\end{btext} \\
\addlinespace
Cool &
\begin{btext}{@{}l@{\ }l@{}}
No: & 1 \\
Yes: & 3
\end{btext}
\end{btext}
\]
\end{document}
已定义列左侧无填充,列间有正常间距。借助booktabs
工具,我在行间添加了一些垂直间距。