{"id":10658,"date":"2023-12-09T10:24:56","date_gmt":"2023-12-09T10:24:56","guid":{"rendered":"https:\/\/www.blopig.com\/blog\/?p=10658"},"modified":"2023-12-09T21:58:53","modified_gmt":"2023-12-09T21:58:53","slug":"handy-latex-syntax-i-googled-over-the-years","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2023\/12\/handy-latex-syntax-i-googled-over-the-years\/","title":{"rendered":"Handy LaTeX syntax I Googled over the years"},"content":{"rendered":"\n<p>In an attempt to ease the transition from Word to LaTeX for some of my colleagues (*cough* Alex *cough*) this blog post covers some LaTeX tricks I use most frequently when preparing manuscripts. It&#8217;s pitched at someone who is already familiar with the basic syntax of paragraphs, figures and tables.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>[If you&#8217;re not already doing so, you can ease your job by using Overleaf and starting from one of the many fantastic LaTeX templates available there: <em><a href=\"https:\/\/www.overleaf.com\/latex\/templates\">https:\/\/www.overleaf.com\/latex\/templates<\/a><\/em>]<br><br>1. <strong>Changing the text format<\/strong> is particularly useful when making notes to self about parts of your manuscript that still need to be modified or for highlighting textual changes to reviewers.<br><br>First, ensure the &#8216;xcolor&#8217; package is imported:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\usepackage{xcolor}<\/pre>\n\n\n\n<p>Then to colour a chunk of text in red:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\\color{red}{text to be coloured}}<\/pre>\n\n\n\n<p>To yellow-highlight a chunk of text:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\\colorbox{yellow}{text to be highlighted}}<\/pre>\n\n\n\n<p>Use an &#8220;!&#8221; to tune the intensity of the color:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\\colorbox{yellow!10}{highlights in pale yellow}}\n{\\colorbox{yellow!50}{highlights in strong yellow}}<\/pre>\n\n\n\n<p>Bold text:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\textbf{text to be emboldened}<\/pre>\n\n\n\n<p>Italic text: <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\textit{text to be italicised}<\/pre>\n\n\n\n<p>Underline text: <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\underline{text to be underlined}<\/pre>\n\n\n\n<p>Strikeout text:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\usepackage{soul}\n\\st{text to be struck out}<\/pre>\n\n\n\n<p>2. Got a large landscape figure\/table that needs rotating so that it fits on the page? Use the <strong>rotating<\/strong> package.<\/p>\n\n\n\n<p>For elements rotated 90 degrees anti-clockwise:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\usepackage[figuresright]{rotating}<\/pre>\n\n\n\n<p>For elements rotated 90 degrees clockwise:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\usepackage[figuresleft]{rotating}<\/pre>\n\n\n\n<p>and either:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\begin{sidewaysfigure}\n...\n\\end{sidewaysfigure}<\/pre>\n\n\n\n<p>or:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\begin{sidewaystable}\n...\n\\end{sidewaystable}<\/pre>\n\n\n\n<p>3. <strong>Figure syntax<\/strong> also helps to guide figures to display the way you want them.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\begin{figure}[ht]<\/pre>\n\n\n\n<p>&gt;The letters in the square brackets tell latex where you want the figure. h = here, t = top of page, b = bottom of page. You can supply an exclamation mark to get Latex to ignore some placement restrictions and make the figure more likely to appear where you want it, e.g. <em>\\begin{figure}[ht!]<\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\includegraphics[width=0.9\n\\textwidth]{my_figure.png}<\/pre>\n\n\n\n<p>&gt;If you find your figure isn&#8217;t appearing where you want it to be, it&#8217;s probably violating some margin restriction may need to be shrunk in size to fit. Adding the width tag allows you to adjust the size of the figure relative to the pagewidth and overcome the restriction.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\begin{figure}<\/pre>\n\n\n\n<p>vs<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\begin{figure*}<\/pre>\n\n\n\n<p>&gt;In most two-column latex templates one will render the figure within a single column and the other as a full-page figure that spans both columns.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\begin{table}\n\\begin{tabular}[|l|l|l|]\n\\end{tabular}\n\\end{table}<\/pre>\n\n\n\n<p>&gt; l = left aligned; | = where the column rules will be. So this is a three-column table where there is a vertical line on the left, right, and dividing each column. \\begin{tabular}[lll] would have three left-aligned columns but no vertical lines.<br>alternative letters: c = centre, r = right-aligned<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\begin{tabular}[|l|l|l|l|]\n\\multicolumn{2}{c}{My text centralised spanning the first two columns} &amp; \\multicolumn{2}{c}{My other text centralised spanning the last two columns}\\\\\n...\n\\end{tabular}\n\\end{table}<\/pre>\n\n\n\n<p>&gt;The multicolumn command provides an easy way to format column headings that span multiple columns. The &#8220;c&#8221; letter overrides the &#8220;l&#8221; alignment in the square brackets for these cells only.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\vspace{2cm}\n\\vspace{-0.5cm}<\/pre>\n\n\n\n<p>&gt;Helps space out <strong>or<\/strong> compress components of a figure\/table if the spacing is a bit too tight or too generous. Often handy for captions, but also useful outside of the context of figures\/tables.<\/p>\n\n\n\n<p>4. <strong>Accented characters<\/strong> are called by writing a backslash, followed by the key that represents the accent type [not always obvious], followed by the letter in curly brackets.<br>e.g. <br>soir\u00e9e is written soir\\\u2019{e}e<br>ch\u00e2teau is written ch\\^{a}teau<br>ma\u00f1ana is written man\\~{n}ana<br>\u00c5 is written \\r{A}<br><br>More examples here: <a href=\"https:\/\/en.wikibooks.org\/wiki\/LaTeX\/Special_Characters\">https:\/\/en.wikibooks.org\/wiki\/LaTeX\/Special_Characters<\/a><\/p>\n\n\n\n<p>5. &#8220;<strong>Math mode<\/strong>&#8221; (enclosed with $ tags) can not only useful for writing mathematical equations, but can also provide access to common special characters:<br>e.g.<br>~ (a mid-height tilde) is achieved using $\\sim$ rather than \\textasciitilde, which typically sets it as \u02dc.<br>\u03b1\u03b2TCRs is written as $\\alpha\\beta$TCRs<br>\u2265 is written as $\\geq$<br><br>More examples here: <a href=\"https:\/\/www.cmor-faculty.rice.edu\/~heinken\/latex\/symbols.pdf\">https:\/\/www.cmor-faculty.rice.edu\/~heinken\/latex\/symbols.pdf<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In an attempt to ease the transition from Word to LaTeX for some of my colleagues (*cough* Alex *cough*) this blog post covers some LaTeX tricks I use most frequently when preparing manuscripts. It&#8217;s pitched at someone who is already familiar with the basic syntax of paragraphs, figures and tables.<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","wikipediapreview_detectlinks":true,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[296,14,463,30,48],"tags":[],"ppma_author":[532],"class_list":["post-10658","post","type-post","status-publish","format-standard","hentry","category-hints-and-tips","category-howto","category-latex","category-links","category-publication"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":532,"user_id":45,"is_guest":0,"slug":"matt","display_name":"Matthew Raybould","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/71f525eb0d7861fad46de36f6b8f3a4cfd89c5cc6b13e48c5dc6e79a82c5b591?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/10658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/users\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=10658"}],"version-history":[{"count":5,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/10658\/revisions"}],"predecessor-version":[{"id":10676,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/10658\/revisions\/10676"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=10658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=10658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=10658"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=10658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}