2

I would like to include following margin notes into my document:

enter image description here

How can I include such grey lines shown in this image above and below my notes? Also, my margin notes are entirely cut off:

enter image description here

I am using document class book, and the following command:

\documentclass[a4paper]{book}

\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{cite}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{subfigure}
\usepackage{listings}
\usepackage{framed}
\usepackage{multicol}
\usepackage{color}
\usepackage{graphics}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{caption}
\usepackage{comment}
\usepackage{hyperref}
\usepackage[english]{babel}
\usepackage{makecell}
\usepackage[left=3.5cm]{geometry}
\usepackage{capt-of}
\usepackage{algorithm2e}
\usepackage{wrapfig}
\usepackage{floatflt}
\usepackage{acro}
\usepackage[acronym]{glossaries}
\usepackage[refpage]{nomencl}
\usepackage{blindtext}
\usepackage[most]{tcolorbox}
\usepackage{graphicx}
\setlength\parindent{0ex}
\graphicspath{ {figures/} }
\usepackage{titlesec}
\usepackage{marginnote}
%\usepackage[dvipsnames]{xcolor}

\definecolor{test}{RGB}{138,0,43}


\titleformat{\section}
{\color{test}\normalfont\Large\bfseries}
{\color{test}\thesection}{1em}{}


\title{Draft }
\author{test}
 \raggedbottom
\begin{document}
\maketitle



\chapter{Introduction}



\section{Introduction}
\label{sec:intro}


Test test

\marginpar{{\color{brown}BOLD} This is a margin note 
using the geometry package, set at 
3cm vertical offset to the line it is typeseted.}

\end{document}
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user36296 Apr 1 '18 at 18:11
  • 1
    your image suggests that you have set \marginparwidth wider than the margin, but as you have shown no example code it is not possible to say where your code is wrong. please post a small but complete document that shows the problem – David Carlisle Apr 1 '18 at 18:11
  • Ok will do!......... – Pegah Apr 1 '18 at 18:15
  • @Pegah your code is not minimal. I doubt that e.g. mathtools is necessary to reproduce your issue. Also, if this is the preamble of your actual document, don't include blindtext. That package is just for dummy creation and I don't think you need dummy text in your work. – Skillmon Apr 1 '18 at 18:21
  • Also there is no need to load graphics if you load graphicx, same for color and xcolor. – Skillmon Apr 1 '18 at 18:30
3

Include \rules in your \marginpar:

\documentclass[]{article}

\usepackage{duckuments}
\usepackage{xcolor}

\newcommand\marginrule{\textcolor{gray}{\rule{\marginparwidth}{.4pt}}}
\newcommand\mymarginpar[1]
  {%
    \marginpar{\marginrule\\#1\\[-0.5\baselineskip]\marginrule}%
  }

\begin{document}
\blindduck[1]
\mymarginpar{Ducks are awesome, but rabbits are better}%
\blindduck[2]

\end{document}

Alternative version using \toprule and \bottomrule of the booktabs package instead of custom rules:

\documentclass[]{article}

\usepackage{duckuments}
\usepackage[table]{xcolor}
\usepackage{booktabs}

\newcommand\mymarginpar[1]
  {{%
    \arrayrulecolor{gray}%
    \marginpar{\begin{tabular}[t]{@{}p{\marginparwidth}@{}}\toprule
    #1\\\bottomrule\end{tabular}}%
  }}

\begin{document}
\blindduck[1]
\mymarginpar{Ducks are awesome, but rabbits are better}%
\blindduck[2]

\end{document}

Setup to include geometry:

\marginparwidth=4cm % change this to your liking
\usepackage
  [inner=3.5cm,outer=\dimexpr\marginparwidth+2\marginparsep\relax]
  {geometry}

It calculates the outer margin based on your \marginparwidth. Consider that a line width of more than about 80 characters (no fixed value here, depends on baseline skip and font size) makes a document considerably harder to read. (the above results in something around 88.6 characters per line).

  • works! which command helps my keeping the notes inside the page's border? – Pegah Apr 1 '18 at 18:22
  • @Pegah I just didn't fiddle with the page layout in this code. I'll take a look at the code you provided in your question. – Skillmon Apr 1 '18 at 18:24
  • @Pegah the problem is caused by the way you load the geometry package. I'll work something out, give me a minute. – Skillmon Apr 1 '18 at 18:31
  • 1
    @Pegah if you are not forced to include geometry to match a page layout, consider not using it at all. The default page layout of the standard classes are considered good typography and make a document easier to read (though it might seem like a waste of space to unexperienced typographers). – Skillmon Apr 1 '18 at 18:45
  • Thank you so much for your time & help!! This was btw also the reason I did not remove the extra packages from the "minimal example"...I thought that something not directly relevant might interfere...- when I remove geometry, the pages are extremly narrow (huge margin left and right), why is that? – Pegah Apr 1 '18 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.