5

I want to use Courier font for an example sentence but it makes the line overflow...

I am using the following code:

\usepackage{courier}

\begin{document}

\section{Introduction}
RE is a task of extracting relations among lexical components in natural language 
text. This paper focuses on extracting binary relations between two entities in a 
sentence. The following is an example Wikipedia sentence with two named-entities 
annotated:\\

\texttt{"Knockin' on Heaven's Door" is a song written and sung by Bob Dylan, 
for the soundtrack of the 1973 film Pat Garrett and Billy the Kid.}\\

In the example sentence above, \textit{Knockin' on Heaven's Door} and 
\textit{Bob Dylan} are annotated as named-entities. Then two DBpedia properties, 
\textit{dbo:composer} (from e1 to e2) and \textit{dbo:musicBy} (from e1 to e2), 
can be extracted as relations between the entity pair.

\end{document}

In the screen shot bellow, example line (in Courier font) reaches to right margin. ('by' is out of the body!)

enter image description here

I want the example sentence to fit inside the body and not reaching into the margin. How can I solve this problem?

  • see https://tex.stackexchange.com/a/368344/36296 – samcarter_is_at_topanswers.xyz May 12 '17 at 11:05
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – jjdb May 12 '17 at 11:09
  • Welcome! We can't possibly give specific advice without a complete example because we don't know which class you are using, what size font, what size paper, how wide margins etc. microtype may help, however. – cfr May 12 '17 at 11:10
  • @jjdb I had just omitted it but I added it now. Please give me an advice! – GyuHyeon Choi May 12 '17 at 11:17
  • @cfr I'm using a Conference template so I cannot change anything. Is there Courier font which does not cause line overflow? – GyuHyeon Choi May 12 '17 at 11:20
  • There's still the \documentclass{...} missing. Have you checked the link above provided by samcarter? – jjdb May 12 '17 at 11:21
  • It is unlikely that a conference template will let you override their choice of fonts. Are you sure you're allowed to do that? – cfr May 12 '17 at 13:02
  • 1
    Solutions were already proposed and accepted before I write this, but keep in mind: Courier is a monospaced font. If you attempt to "squeeze" or "stretch" it by using other methods to change the cursor advance (character spacing), then you are defeating the purpose of Courier. That might be acceptable, however. –  May 12 '17 at 14:37

2 Answers2

5

The quote environment is defined in the LaTeX kernel, so it's quite unlikely that a conference template disallows its usage.

I propose three solutions; each one is implemented as an environment as it should.

Note that \\ should never be used for ending paragraphs and must never precede a blank line. If you want to “leave vertical blank space” use the proper methods with \vspace or \addvspace.

\documentclass{article}
\usepackage{courier}

\newenvironment{ttquote}
 {\quote\ttfamily\raggedright}
 {\endquote}

\newenvironment{ttquotejustify}
 {\par\addvspace{\topsep}%
  \ttfamily\setlength{\spaceskip}{0.3em plus 0.3em}%
  \noindent\ignorespaces}
 {\par\addvspace{\topsep}\ignorespacesafterend}

\newenvironment{ttquotesmall}
 {\quote\ttfamily\raggedright\small}
 {\endquote}

\begin{document}

\section{Introduction}
RE is a task of extracting relations among lexical components in natural language 
text. This paper focuses on extracting binary relations between two entities in a 
sentence. The following is an example Wikipedia sentence with two named-entities 
annotated:
\begin{ttquote}
"Knockin' on Heaven's Door" is a song written and sung by Bob Dylan, 
for the soundtrack of the 1973 film Pat Garrett and Billy the Kid.
\end{ttquote}
In the example sentence above, \textit{Knockin' on Heaven's Door} and 
\textit{Bob Dylan} are annotated as named-entities. Then two DBpedia properties, 
\textit{dbo:composer} (from e1 to e2) and \textit{dbo:musicBy} (from e1 to e2), 
can be extracted as relations between the entity pair.
\begin{ttquotejustify}
"Knockin' on Heaven's Door" is a song written and sung by Bob Dylan, 
for the soundtrack of the 1973 film Pat Garrett and Billy the Kid.
\end{ttquotejustify}
In the example sentence above, \textit{Knockin' on Heaven's Door} and 
\textit{Bob Dylan} are annotated as named-entities. Then two DBpedia properties, 
\textit{dbo:composer} (from e1 to e2) and \textit{dbo:musicBy} (from e1 to e2), 
can be extracted as relations between the entity pair.
\begin{ttquotesmall}
"Knockin' on Heaven's Door" is a song written and sung by Bob Dylan, 
for the soundtrack of the 1973 film Pat Garrett and Billy the Kid.
\end{ttquotesmall}
In the example sentence above, \textit{Knockin' on Heaven's Door} and 
\textit{Bob Dylan} are annotated as named-entities. Then two DBpedia properties, 
\textit{dbo:composer} (from e1 to e2) and \textit{dbo:musicBy} (from e1 to e2), 
can be extracted as relations between the entity pair.

\end{document}

The third solution uses \small so the text becomes less prominent; it is already emphasized by being typeset with reduced margins and a monospaced font. If you prefer it, but also want justification, in the definition change \raggedright into \setlength{\spaceskip}{0.3em plus 0.3em}.

The second solution shows how to define your own environment, should quote be disallowed. Mixing the three approaches is of course possible.

enter image description here

Added for svproc

Here's a definition for ttquote that indents on both sides and justifies the text.

\documentclass{svproc}
\usepackage{courier}

\newenvironment{ttquote}
 {\list{}{\rightmargin=\leftmargin\rightskip=0pt}%
  \ttfamily\setlength\spaceskip{0.3em plus 0.3em}%
  \item\relax}
 {\endlist}

\begin{document}

\section{Introduction}
RE is a task of extracting relations among lexical components in natural language 
text. This paper focuses on extracting binary relations between two entities in a 
sentence. The following is an example Wikipedia sentence with two named-entities 
annotated:
\begin{ttquote}
"Knockin' on Heaven's Door" is a song written and sung by Bob Dylan, 
for the soundtrack of the 1973 film Pat Garrett and Billy the Kid.
\end{ttquote}
In the example sentence above, \textit{Knockin' on Heaven's Door} and 
\textit{Bob Dylan} are annotated as named-entities. Then two DBpedia properties, 
\textit{dbo:composer} (from e1 to e2) and \textit{dbo:musicBy} (from e1 to e2), 
can be extracted as relations between the entity pair.

\end{document}

enter image description here

egreg
  • 1,121,712
3

Please don't use \\ for paragraph breaks!


From https://tex.stackexchange.com/a/368344/36296

\documentclass{article}

\usepackage{courier}

\begin{document}

\section{Introduction}
RE is a task of extracting relations among lexical components in natural language 
text. This paper focuses on extracting binary relations between two entities in a 
sentence. The following is an example Wikipedia sentence with two named-entities 
annotated:

\bigskip
\texttt{\spaceskip=.3em plus 0.2em minus .1em "Knockin' on Heaven's Door" is a song written and sung by Bob Dylan, 
for the soundtrack of the 1973 film Pat Garrett and Billy the Kid.}
\bigskip

In the example sentence above, \textit{Knockin' on Heaven's Door} and 
\textit{Bob Dylan} are annotated as named-entities. Then two DBpedia properties, 
\textit{dbo:composer} (from e1 to e2) and \textit{dbo:musicBy} (from e1 to e2), 
can be extracted as relations between the entity pair.

\end{document}

enter image description here

jjdb
  • 2,238