18.4.15

Redimensionar Tablas en LaTeX

Como se menciono anteriormente al realizar tablas en LaTeX es necesario vigilar manualmente el grosor de la tabla para evitar que la tabla sea mas ancha que la pagina y se "corte".


Sin embargo existe una sencilla para prevenir esos casos, a la vez que le da a la tabla una apariencia mas procesional, el comando \resizebox.

Este comando toma como argumento el ancho que deseamos tenga la tabla y la escala adecuadamente cambiando el tamaño de letra y grosor de las lineas, logrando que la tabla solo tenga el ancho indicado.

Para poder hacer uso de este comando es necesario incluir el paquete graphicx que viene incluido en la instalación por defecto tanto de Tex Live como de MikTeX.

El formato de este comando es el siguiente:

\resizebox{}{!} {


}

Es muy importante poner las llaves ya que estas delimitan donde tendrá efecto el comando.

Ahora se presentara un pequeño ejemplo con el fin de ilustrar el efecto del comando

Para esto en un documento LaTeX que contenga las declaraciones necesarias (\documentclass , \begin{document}, etc) agrege este codigo

\begin{table}
\centering
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
\hline
\multicolumn{5}{|c|}{Puerto fuente} & \multicolumn{4}{|c|}{Puerto destino} \\ \hline
\multicolumn{9}{|c|}{Numero de secuencia} \\ \hline
\multicolumn{9}{|c|}{Numero de reconocimiento} \\ \hline
Longitud cabecera & Reservado & URG & ACK & PSH & RST & SYN & FIN & Tamaño ventana \\ \hline
\multicolumn{5}{|c|}{Suma verificación} & \multicolumn{4}{|c|}{Puntero a datos urgentes} \\ \hline
\multicolumn{9}{|c|}{Opciones} \\ \hline
\multicolumn{9}{|c|}{Datos} \\ \hline
\end{tabular}
\caption{Estructura de un segmento TCP.}
\label{c2_tabla_segento_tcp}
\end{table}

El cual generara una tabla como la mostrara el la figura 1

Figura 1: Tabla sin redimensionar.
Notara que la tabla queda "cortada" por el borde de la pagina y parte del contenido queda fuera vista.

Ahora remplace el codigo de la tabla por este:

\begin{table}
\centering
\resizebox{10cm}{!} {
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
\hline
\multicolumn{5}{|c|}{Puerto fuente} & \multicolumn{4}{|c|}{Puerto destino} \\ \hline
\multicolumn{9}{|c|}{Numero de secuencia} \\ \hline
\multicolumn{9}{|c|}{Numero de reconocimiento} \\ \hline
Longitud cabecera & Reservado & URG & ACK & PSH & RST & SYN & FIN & Tamaño ventana \\ \hline
\multicolumn{5}{|c|}{Suma verificación} & \multicolumn{4}{|c|}{Puntero a datos urgentes} \\ \hline
\multicolumn{9}{|c|}{Opciones} \\ \hline
\multicolumn{9}{|c|}{Datos} \\ \hline
\end{tabular}
}
\caption{Estructura de un segmento TCP.}
\label{c2_tabla_segento_tcp}
\end{table}

Y recompile el documento, el resultado ahora lucirá como la Figura 2
Figura 2: Tabla redimensionada.

Ahora la tabla cabe perfectamente en la pagina y su contenido es perfectamente visible.

17.4.15

Create Search Link Between TeXstudio and SumatraPDF

I use TeXstudio for my LaTeX works. SumatraPDF is also good, lightweight PDF reader. It is possible to create a forward search from TeXstudio to SumatraPDF. You may find PDF output of a LaTeX code. Similarly, a backward search is possible: find LaTeX source code from PDF output.


Note: This post will be based on http://robjhyndman.com/hyndsight/texstudio-sumatrapdf/ . But since it was published in 2011, there are some slight changes in software menus. You may also read it. 

1 - Open TexStudio. Navigate Options -> Configure TeXstutdio...

TeXstudio options
Configure TeXstudio...


2 - Click Commands tab, and find External PDF Viewer option.
External PDF Viewer
External PDF Viewer
3 - Change it like:

"C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe" -reuse-instance %.pdf

You should put your path to SumatraPDF.exe between quotation marks.

Update (08 Feb 2015): I use pdflatex. According to Vojtech Vozda (see comments), if you use DVI -> PS ->PDF chain you should also add -synctex=1 option to LaTeX part as in PdfLaTeX option in order to create search link between your source code and PDF file. See also: What exactly is SyncTeX?

4 - Click Build tab, find PDF Viewer option and change it to External PDF Viewer.
Use External PDF Viewer
Use External PDF Viewer
5 - At same window, locate User Commands tab.

User Commands
User Commands

Add the following statements:


user0:Forward Search

to first column and

dde:///"C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe":SUMATRA/control/  [ForwardSearch("?am.pdf","?c:am.tex",@,0,0,1)]

to second column.

You should put your path to SumatraPDF.exe between quotation marks.

Click OK.

6 - Now let's open Options -> Configure TeXstutdio...  again and select Shortcuts tab. ExpandMenus -> Tools -> User tree. Now you should see a user command called Forward Search. Now its default shortcut is Alt+Shift+F1. But you can also assign another shortuct to forward search likeF2. But this step is optional.
User Commands Shortcut
User Commands Shortcut
7 - Now we are done with TeXstudio. Let's set up SumatraPDF. Open SumatraPDF. Click Settings -> Options.
Sumatra Settings
Sumatra Settings
8 - Locate Set inverse search command-line.
Sumatra Inverse Search
Sumatra Inverse Search
Type:


"C:\Program Files (x86)\TeXstudio\texstudio.exe" "%f" -line %l

You should put your path to texstudio.exe between quotation marks.

Click OK and exit.

Now let's try your new setup.

Compile a LaTeX code in TeXstudio and produce PDF output. If you press F2 (if you assign that shortcut in TeXstudio settings), SumatraPDF should highlight corresponding output of your cursor position. In SumatraPDF, double-clicking shows corresponding LaTeX code in TeXstudio.

Getting started with XeLaTeX

By now, most LaTeX users have prob­a­bly heard of XeLa­TeX, if only because it is an option in the lat­est ver­sions of the stan­dard LaTeX edi­tors such as TeXnic­Cen­ter,WinEdt and TeX­Works. But most LaTeX­ers have prob­a­bly not yet become XeLa­TeX­ers. Why should you?
XeLa­TeX is essen­tially a replace­ment for pdfLa­TeX. It was pri­mar­ily devel­oped to enable bet­ter font han­dling, espe­cially non-​​Roman scripts. If you want to write in Tel­ugu, then XeLa­TeX is going to make your life much eas­ier. For Eng­lish writ­ers, the main ben­e­fit of XeLa­TeX is the abil­ity to use the fonts on your com­puter, just as you can with other soft­ware. If you’ve grown to love using Geor­gia in MS-​​Word and always wanted to write a LaTeX doc­u­ment in Geor­gia, now you can.
Here is a very sim­ple example:
\documentclass{article}
\usepackage{fontspec,lipsum}
\defaultfontfeatures{Ligatures=TeX}
\usepackage[small,sf,bf]{titlesec}
 
\setromanfont{Georgia}
\setsansfont{Tahoma}
 
\begin{document}
\section{Introduction}
 
\lipsum[1]
 
\section{Nonsense}
 
\lipsum[2-4]
\end{document}
Note the fol­low­ing features:
  • The fontspec pack­age is almost always nec­es­sary with XeLa­TeX and con­tains com­mands to load the required fonts.
  • You usu­ally need the com­mand \defaultfontfeatures{Ligatures=TeX}. This is so the new fonts behave in the way we’ve come to expect with LaTeX, such as allow­ing an em-​​dash to be writ­ten as ---.
  • The two fonts that are loaded (Geor­gia and Tahoma in this exam­ple) are fonts avail­able in my Win­dows fonts directory.
  • The titlesec pack­age is loaded only so head­ings are in sans-​​serif bold in order to show the effect of the font changes.
  • The lip­sum pack­age pro­vides some non­sense text for test­ing purposes.
A dis­ad­van­tage of using XeLa­TeX is that most of the fonts on your com­puter will not come with enough fancy char­ac­ters (known as glyphs) for math­e­mat­ics. So maths has to be set using a stan­dard LaTeX font. Con­se­quently, I am not using XeLa­TeX for my math­e­mat­i­cal doc­u­ments, but I have started try­ing it out on non-​​mathematical documents.
For a lot more infor­ma­tion, read the fontspec man­ual.

Tables in LaTeX

Mak­ing tables in LaTeX is one of the few areas where LaTeX is more dif­fi­cult than a WYSIWYG editor.
Here are some point­ers to tools and pack­ages that I have found useful.
  • Excel2LaTeX: this excel add-​​in makes it easy to copy a rec­tan­gu­lar array of cells in a spread­sheet into a LaTeX document.
  • Calc2LaTeX: a sim­i­lar exten­sion for Libre­Of­fice and OpenOffice.
  • The LaTeX wik­i­book has a great page on pro­duc­ing tables in LaTeX.
  • Toolkit Instal­la­tor:this is a col­lec­tion of add-​​ins for WinEdt. It con­tains two fea­tures that are use­ful for tables.
    1. A graphic table designer for inputting sim­ple tables.
    2. A util­ity for mak­ing exist­ing tables neat by lin­ing up the & and remov­ing unnec­es­sary space.
  • Tuto­ri­als on tables from the Indian TeX users group:
    1. The basics
    2. Long tables
    3. Coloured tables
  • The array pack­age for apply­ing for­mat­ting com­mands to whole columns and pro­vid­ing addi­tional for­mat­ting options for paragraph-​​like columns.
  • The tab­u­larx pack­age for set­ting a table with fixed-​​width and para­graph columns with width auto­mat­i­cally calculated.
  • The book­tabs pack­age for pro­vid­ing nicer hor­i­zon­tal lines and bet­ter spac­ing control.
  • The longta­bles pack­age for tables that are too big for a sin­gle page.
  • Type­set­ting tables with LaTeX: a nice (and short) arti­cle cov­er­ing the basics as well as the above four packages.
  • Type­set­ting tables with LaTeX: video of Klaus Höpp­ner giv­ing a talk based on the above article.

Generating tables in LaTeX

Typ­ing tables in LaTeX can get messy, but there are some good tools to sim­plify the process. One I dis­cov­ered this week is tables​gen​er​a​tor​.com, a web-​​based tool for gen­er­at­ing LaTeX tables. It also allows the table to saved in other for­mats includ­ing HTML and Mark­down. The inter­face is sim­ple, but it does most things. For com­pli­cated tables, some addi­tional for­mat­ting may be necessary.

Screenshot from 2014-04-15 08:57:38

Sim­i­lar func­tion­al­ity is avail­able via plu­g­ins in ExcelOpenOf­fice and Libre­of­fice — use­ful if the data for the table is already stored in a spreadsheet.
Good LaTeX edi­tors also have built-​​in table gen­er­a­tors. For exam­ple, TeX­studio has the “Quick tab­u­lar wiz­ard” and TeX­maker has the “Tab­u­lar wiz­ard”. The one in TeX­studio is too sim­ple to be very use­ful, but the TeX­maker wiz­ard has a few more features.
Another use­ful tool to avoid the mess is the “Align columns” func­tion within TeX­studio (nor­mally shown as a blue but­ton at the top of the screen). Place the cur­sor within a table and click the but­ton, and spaces are mag­i­cally added until the columns are aligned. It also works for align, array and matrix envi­ron­ments. Here is a small exam­ple from a recent paper of mine show­ing what it does.
Before:
Screenshot from 2014-04-15 09:25:44
After:
Screenshot from 2014-04-15 09:17:22
It is much eas­ier to spot prob­lems if the columns are aligned.

Cahnge profile in TXS

It is pos­si­ble to save the scheme in a pro­file file, and then load it on another com­puter. Sev­eral dark themes have been pro­posed on TeX​.stack​ex​change​.com. I edited one of them to cre­ate my own theme shown below.
Screenshot from 2015-03-18 13:11:22
Here is the pro­file file that imple­ments the above scheme. You should be able to load it in TeX­studio (after which you will need to re-​​start TeX­studio to see the effect).

Using TeXstudio with SumatraPDF

Tomado de http://robjhyndman.com/hyndsight/texstudio-sumatrapdf/

Suma­traPDF is my favourite pdf reader and TeX­studio is my favourite LaTeX edi­tor. Here’s how to get them to work nicely together.
Go to Options/​Configure TeX­studio and click on “Com­mands”. Beside Pdf Viewer, untick “Inter­nal viewer” and add the fol­low­ing command:
"c:/Program Files/SumatraPDF/SumatraPDF.exe" -reuse-instance %.pdf
(If you have Suma­traPDF stored some­where other than the spec­i­fied paths, you will need to edit this accordingly.)
Then you need to tell Suma­traPDF how to jump to the cor­rect line in TeX­studio. From within Suma­traPDF, go to Settings/​Options and set the inverse search com­mand to
"C:\Program Files\TeXstudio\texstudio.exe" "%f" -line %l
Change the path to TeX­studio if necessary.
In order to go from the tex file to the cor­re­spond­ing loca­tion in the pdf, you can add a For­ward­Search com­mand within TeX­studio. Select “User” from the main menu, then “User com­mands” and “Edit User com­mands”. Then add a com­mand with the fol­low­ing definition:
dde://"C:/Program Files/SumatraPDF/SumatraPDF.exe":SUMATRA/control/
  [ForwardSearch("?am.pdf","?c:am.tex",@,0,0,1)]
(That should all be on one line with no space before [ForwardSearch. Again, edit the path for Suma­traPDF as nec­es­sary. Give the com­mand a name such as “For­ward­Search” and click “OK”. Now you should be able to jump to the cor­re­spond­ing part of the pdf file using “Alt-​​Shift-​​F1” (or what­ever key-​​combination is asso­ci­ated with your new command).
Being lazy, I pre­fer a sim­ple func­tion key. To map F2 to your new com­mand, select “Options/​Configure TeX­studio” and choose “Short­cuts”. Find your new com­mand under the User menu, dou­ble click to the right of it and select “F2” from the drop-​​down box. Pre­vi­ously F2 was mapped to LaTeX, but I never use LaTeX directly, so los­ing this func­tion is no problem.
Now you can dou­ble click on any part of the pdf from within Suma­traPDF and it should take you to the cor­re­spond­ing place in your tex file in TeX­studio. And thenF2 will take you back again.

Synchronizing WinEdt and pdf files

Tomado de http://robjhyndman.com/hyndsight/synchronizing-winedt-and-pdf-files/

Being able to go from a line in WinEdt to the cor­re­spond­ing place in a com­piled doc­u­ment is extremely use­ful and saves a lot of time. This has long been pos­si­ble using Yap with dvi doc­u­ments, but Yap is slow and ugly and the dvi files usu­ally have to be con­verted to pdf before send­ing them to any­one else.
So I tend to use pdf­tex­ify to cre­ate pdf files directly, but I miss hav­ing syn­chro­niza­tion between what I write and the pdf file that is created.
How­ever, I’ve found a solu­tion that is not too dif­fi­cult to imple­ment and seems to work well. It replaces the Adobe pdf reader with Suma­traPDF.  There is some fid­dling of set­tings in WinEdt as explained in the instruc­tions below. The infor­ma­tion below is adapted from William Blum’s web­site.
  1. Down­load Suma­traPDF and install it to the (default) direc­tory c:\Program files\SumatraPDF
  2. For Winedt 6.0
    Run WinEdt and go to Options/​Execution Modes. Click on the “PDF Viewer” tab and click the “Suma­tra PDF” but­ton. Make sure the box under “Sync Tex” is ticked. Then click “OK”. That’s it!
  3. For Winedt 5.6.
    1. Down­load Acro­bat OpenDoc.edt and Sumatra-Find.edt and save them to C:\Program Files\WinEdt Team\WinEdt\Exec
    2. Run WinEdt and go to Options/​Execution Modes. Click on the “Acro­bat” tab and replace the path to the “PDF Viewer Exe­cutable” with"C:\Program files\SumatraPDF\SumatraPDF.exe" -reuse-instance. Like this: 
    3. Before clos­ing the dia­log box, go to the “Con­sole Appli­ca­tions” tab and select “PDF­Tex­ify”. Change the switches field to--pdf --tex-option=--synctex=-1Sim­i­larly, for PDFLa­TeX and PDF­TeX, change the switches fields to--synctex=-1Then click “OK”.
    4. In WinEdt, go to the menu ‘Option/​Menu setup’. Cre­ate a new macro menu some­where (under ‘Acces­sories’ for instance) and fill the options as follows:
        Name: Sumatra Find
        Macro: Exe('%b\Exec\Sumatra-Find.edt');
        Requires File Fil­ter: %P\%N.pdf
        Start in: %P
        Short­cut: Shift-F8
      Now when edit­ing a .tex file in WinEdt, you can go to the cor­re­spond­ing line in the pdf doc­u­ment by press­ing Shift-​​F8.

Update

  • The above instruc­tions only work with Mik­TeX (tested on Mik­TeX 2.7 and 2.8). If you use TeXLive, or some other LaTeX imple­men­ta­tion, then you will need to fig­ure it out for yourself.
  • You should not use the pdfsync package.
  • Some peo­ple have reported trou­ble with beamer. I have had no dif­fi­cul­ties using beamer with the above settings.
  • The above instruc­tions have now been updated (8 Sep 2009) to take account of all com­ments below.