编号 \newcommand 不带枚举

编号 \newcommand 不带枚举

如何在章节和章节内添加编号问题,但不添加enumerate

问题必须具有如下定义的变量。

\documentclass[10pt,a4paper,oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\newcommand{\prob}[1]{\vspace{.5cm}\noindent\textbf{\textsc{Problem}} $\left[#1 \right]$}
\begin{document}
\section{My first section}
\prob {1} This is problem. 

\end{document}

答案1

这是编辑的解决方案

\documentclass[10pt,a4paper,oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\newcounter{pro}[section]
\renewcommand{\thepro}{\thesection.\arabic{pro}}

\newcommand{\prob}[1]{%
\refstepcounter{pro}%
\par\vspace{.5cm}\noindent\textbf{\thepro.\quad\textsc{Problem} [#1] }}
\begin{document}
\section{My first section}
\prob{4}  This is problem. 
\prob{6}  This is problem. 
\end{document}

评论对于粗体小写字母,这是另一个问题

答案2

这是使用titlesec软件包的解决方案;\problem命令是未编号的子节。titlesec 软件包有一个unnumbered键,允许对编号和未编号的子节使用不同的格式。不过,问题将自动使用特别指定 计数器,它们可以有一个标题作为可选参数。由于这些子节很可能是唯一一种未编号的子节,因此它不应该干扰文档的其他设置。

笔记。我加载了该erewhon包(Adobe Utopia 的一个扩展),因为你似乎想要一种粗体小型大写字体,而 Latin Modern 中不存在这种字体。

\documentclass[10pt,a4paper,oneside]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier, erewhon}
\usepackage{amsfonts, amssymb}
\usepackage[margin=3cm, showframe]{geometry}
\usepackage{etoolbox}

\usepackage[explicit]{titlesec}
\newcounter{problem}[section]
\newcommand\problem[1][]{\subsection*{#1}}
\titleformat{name=\subsection, numberless}[runin]%
{\stepcounter{problem}}{\bfseries\scshape{Problem~[\theproblem]}}%
{0.4em}{\ifblank{#1}{\hskip-0.333em.}{(#1).}}

\begin{document}

\section{A first section}

Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.

\problem[Test problem]
A first problem, with a title.

\problem
A second problem.

\bigskip

Some more text. Some more text. Some more text. Some more text. Some more text.

\section{A second section}

Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.

\problem[New test problem]
Another problem with a title.

\problem
A final problem.

\bigskip

Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.

\end{document} 

在此处输入图片描述

相关内容