1

I want to realize something like in this two pictures. I want to use a part of the margins for notes (draw even tables!). I want that the margin change from odd page to even page (I think it's simple to find how but if you tell me how I will appreciate that). My problem is that when I draw a table it doesn't use the left margin so a part of it is not shown as it existed the right margin. So how to tell the table to use the left margin? My question is not only for table but for all box (listing code, figures ...etc). I have tried to chngpage package but it doesn't work for me.

I want to have something that let me specify the left and right margin (the table should never be drawn outside this margins) and if it is small it will be centered.

enter image description here enter image description here

MWE

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{booktabs,caption,fixltx2e}
\usepackage{chngpage}
\usepackage{lipsum}
\usepackage[flushleft]{threeparttable}
\usepackage{hhline}
\usepackage{xcolor,colortbl}
\usepackage[top=2.5cm, bottom=2.5cm, left=8cm, right=2.5cm, heightrounded,
  marginparwidth=7cm, marginparsep=3mm]{geometry}
\usepackage{hyperref}
\usepackage{minted}
\begin{document}
  \lipsum[1]
  \begin{adjustwidth}{-6in}{-6in}
  \begin{table}
  \begin{threeparttable}
    \caption{\label{comparaison}  Comparaison entre JSON, XML et 
multipart/form-data}
\begin{tabular}{|>{\raggedright\arraybackslash}p{2cm}|>{
\raggedright\arraybackslash}p{3cm}|>{\raggedright\arraybackslash}p{3cm}|>{
\raggedright\arraybackslash}p{3.5cm} |}
\hhline{~---}
\multicolumn{1}{c|}{} & \cellcolor{gray!30} JSON & \cellcolor{gray!30} XML & 
\cellcolor{gray!30} multipart/form-data \\
\hline
\cellcolor{gray!30} Taille des données &
Trop léger et économise des ressources  &
trop verbeux mais en utilisant la compression on pourrait réduire 
considérablement la taille de données &

Trop léger\\
\hline

\cellcolor{gray!30} Typage &
Il support les types de base (entier, booleen, chaîne de caractères, tableau  
liste) &
Il supporte beaucoup de types de données &
non typée \\
\hline
\cellcolor{gray!30} Caractères non ASCII &
JSON est encodé en UTF-8 &
Possibilité d'encoder la requête en UTF-8 &
Possibilité d'utiliser UTF-8 comme encodage \\
\hline
\cellcolor{gray!30} données binaires &
Les données doivent être encodé (base64 par exemple) &
Comme pour le format JSON les données doivent être encodées &
C'est possible \\
\hline
\cellcolor{gray!30} Parseur Python/Java &
Il est pris en charge par Python. Besoin d'une librairie externe en Java &
Il pris en charge en Python/Java &
Pris en charge en Python/Java \\
\hline

\end{tabular}
\begin{tablenotes}
      \small
      \item \textbf{Source :} 
\begin{itemize}
 \item 
\href{http://stackoverflow.com/questions/4007969/}{Réponse de manuel aldana}
\item \href{http://www.scriptol.fr/ajax/json-xml.php}{JSON ou XML, quel format 
choisir?}
\end{itemize}

    \end{tablenotes}
  \end{threeparttable}
\end{table}
\end{adjustwidth}
\lipsum[1]

\newpage
\begin{minted}[mathescape,
               linenos,
               numbersep=5pt,
               gobble=2,
               frame=lines,
               framesep=2mm]{json}
{
  "culture precedente": "Tournesol",
  "culture principale" : "Blé",
  "parcelle" : "BI",
  "test line " : "very long long long long long long long long long long long long long long long line"
  "parameters" : {
    "start" : "2010-07-12 12:00:00",
    "end" : "2012-01-12 12:00:00",
    "pram1" : "value",
    "param2" : "value"
  },

  "results" : { 
      "numeric" : ["QELS", "WCF30"],
      "graph" : [{
          "X" : "time",
          "Y" : "QELS"
      }]
    }
}
\end{minted}
Voici un exemple de réponse : 
\begin{minted}[mathescape,
               linenos,
               numbersep=5pt,
               gobble=2,
               frame=lines,
               framesep=2mm]{json}
{
  "results" : {
    "QELS" : 1.254,
    "WCF30" : 200.745,
    "graph" : [
        "http://toulouse.inra.fr/api/files/graph.png" 
        ] 
  }
}
\end{minted}  

\end{document}

Result (Edited)

enter image description here enter image description here

2

For tabulars which are wider than textwidth use:

\begin{table}[!htb]

\hspace*{-\marginwidth}\makebox[\totalwidth][r]{%

   \begin{threeparttable}
     ....
   \end{threeparttable}%
}
\end{table}

And for smaller ones:

\begin{table}[!htb]
   \centering
   \begin{threeparttable}
     ....
   \end{threeparttable}%
\end{table}

enter image description here

The complete code, which defines two length for the correct width:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{booktabs,caption,fixltx2e}
\usepackage{chngpage}
\usepackage{lipsum}
\usepackage[flushleft]{threeparttable}
\newcolumntype{P}[1]{>{\RaggedRight}p{#1}}
\usepackage{hhline}
\usepackage{ragged2e}
\usepackage[table]{xcolor}

\usepackage[top=2.5cm, bottom=2.5cm, left=8cm, right=2.5cm, heightrounded,
  marginparwidth=7cm, marginparsep=3mm]{geometry}
\usepackage{hyperref}

\newlength\marginwidth
\setlength\marginwidth{\dimexpr\marginparwidth+\marginparsep}
\newlength\totalwidth 
\setlength\totalwidth{\dimexpr\textwidth+\marginwidth}

\begin{document}
  \lipsum[1]

\begin{table}[!htb]
\hspace*{-\marginwidth}\makebox[\totalwidth][r]{%
 \begin{threeparttable}
 \caption{\label{comparaison}  Comparaison entre JSON, XML et 
multipart/form-data}
\begin{tabular}{|>{\columncolor{gray!30}}P{2cm}|P{3cm}|P{3cm}|P{3.5cm} |}
\hhline{~---}
\multicolumn{1}{c|}{} & \cellcolor{gray!30} JSON & \cellcolor{gray!30} XML & multipart/form-data \\ \hline
Taille des données &
Trop léger et économise des ressources  &
trop verbeux mais en utilisant la compression on pourrait réduire 
considérablement la taille de données &
Trop léger\\
\hline
Typage &
Il support les types de base (entier, booleen, chaîne de caractères, tableau  
liste) &
Il supporte beaucoup de types de données &
non typée \\
\hline
Caractères non ASCII &
JSON est encodé en UTF-8 &
Possibilité d'encoder la requête en UTF-8 &
Possibilité d'utiliser UTF-8 comme encodage \\
\hline
données binaires &
Les données doivent être encodé (base64 par exemple) &
Comme pour le format JSON les données doivent être encodées &
C'est possible \\
\hline
Parseur Python/Java &
Il est pris en charge par Python. Besoin d'une librairie externe en Java & 
Il pris en charge en Python/Java &
Pris en charge en Python/Java \\ \hline
\end{tabular}
\begin{tablenotes}
      \small
      \item \textbf{Source :} 
\begin{itemize}
 \item 
\href{http://stackoverflow.com/questions/4007969/}{Réponse de manuel aldana}
\item \href{http://www.scriptol.fr/ajax/json-xml.php}{JSON ou XML, quel format 
choisir?}
\end{itemize}
    \end{tablenotes}
  \end{threeparttable}%
}
\end{table}

\lipsum[1]
\end{document}
  • Thanks but your code doesn't work for minted code. – Hunsu May 19 '14 at 9:59
  • 1
    I cannot see any minted code in your example. – user2478 May 19 '14 at 10:29
  • I will put some. In my question I said that solution should work not only for tables. – Hunsu May 19 '14 at 10:35
  • I have edited my question. I want the code to be centered which means it will use part of the left margin. – Hunsu May 19 '14 at 10:42
  • Your solution doesn't work if the table is in a even page. see imgur.com/6rnOWCs – Hunsu May 19 '14 at 11:48

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.