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?

8
  • see tex.stackexchange.com/a/368344/36296 Commented May 12, 2017 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
    Commented May 12, 2017 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
    Commented May 12, 2017 at 11:10
  • @jjdb I had just omitted it but I added it now. Please give me an advice! Commented May 12, 2017 at 11:17
  • 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.
    – user103221
    Commented May 12, 2017 at 14:37

2 Answers 2

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

5
  • Beautiful! You are amazing! Commented May 12, 2017 at 13:18
  • I used \begin{ttquote} but its toothed. What should I do? Commented May 12, 2017 at 13:23
  • @GyuHyeonChoi Without knowing about your template, I can't say. The term is “indented”, by the way.
    – egreg
    Commented May 12, 2017 at 13:24
  • I'm using svproc provided by Springer. I want ttquotejustify with more margins on left and right sides. Is it possible? I changed 0.3em's to 0.5em's but nothing is changed. Commented May 12, 2017 at 13:28
  • 1
    @GyuHyeonChoi I added the proper definition.
    – egreg
    Commented May 12, 2017 at 13:42
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

3
  • @TonioElGringo Ask the OP. This would certainly be better, but I cannot know if it would work with the conference template he/she has to use. Commented May 12, 2017 at 11:44
  • @TonioElGringo Maybe you want to add an alternative answer with quote? Commented May 12, 2017 at 11:45
  • It does not answer this specific question, but I recommand to define and use an environment if this type of citation often happens in your documents. Commented May 12, 2017 at 11:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .