我创建了一个环境,但第一段缩进有问题。这是一个最小的例子:
\documentclass[12pt,a4paper]{article}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{mathtools}
\begin{document}
\newif\ifrisposte
\rispostetrue %togli il commento se vuoi i risultati
\newcounter{numquesito}
\newenvironment{domanda}[1]{\stepcounter{numquesito}\par\bigskip\noindent\textbf{\thenumquesito}. \textbf{#1.}\par\medskip\noindent%
}%{\relax}
\ifrisposte
\newenvironment{risposta}[1]{\par\medskip\noindent {\ttfamily \fontseries{b}\selectfont [#1]}}{\par\bigskip}
\else
\excludecomment{risposta}
\fi
\begin{domanda}{Title}
Bad indentation in the first line. Then everything is ok in the second and subsequent lines.
The second paraagraph has a different indentation.
\end{domanda}
\end{document}
结果如下:
我该如何修复该问题?
答案1
的“开始部分”中的代码domanda
开始一个段落,因此之后的结束行在\begin{domanda}{Title}
输出中变成空格。
\ignorespaces
在最后添加。我还建议对代码进行一些其他更改。
\documentclass[12pt,a4paper]{article}
\usepackage[italian]{babel}
%\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{mathtools}
\usepackage{comment}
\newcounter{numquesito}
\newenvironment{domanda}[1]
{%
\stepcounter{numquesito}%
\par\addvspace{\bigskipamount}%
\noindent\textbf{\thenumquesito\ #1.}\par\nopagebreak\medskip\noindent
\ignorespaces
}
{\par\addvspace{\medskipamount}}
\newenvironment{risposta}[1]
{%
\par\addvspace{\medskipamount}%
\noindent{\fontseries{b}\ttfamily [#1] }\ignorespaces
}
{\par\addvspace{\bigskipamount}}
%%%
\newif\ifrisposte
\AtBeginDocument{\ifrisposte\else\excludecomment{risposta}\fi}
%%%
\rispostetrue %togli il commento se vuoi i risultati
\begin{document}
\begin{domanda}{Title}
Bad indentation in the first line. Then everything is ok in the second and subsequent lines.
The second paraagraph has a different indentation.
\end{domanda}
\end{document}
我建议不要使用“硬”垂直空间,而\addvspace
不要累积它们,而只使用最大的一个。\nopagebreak
设置标题后也需要这样做。