JavaScript is disabled. Enabling JavaScript will make this web site awesomer, but it isn't required.

Latest Posts

Excel to LaTeX Tables

table2tabular

So here’s the story: I use LaTeX for creating documents almost exclusively, but making tables are a huge pain. I use Excel all the time for number crunching but I prefer to display results in LaTeX when I’m finished. After doing a bit of googling, I didn’t find anything that I found all that useful, Read MoreRead More

So here’s the story: I use LaTeX for creating documents almost exclusively, but making tables are a huge pain. I use Excel all the time for number crunching but I prefer to display results in LaTeX when I’m finished. After doing a bit of googling, I didn’t find anything that I found all that useful, so I decided to write some VBA to convert Excel tables to LaTeX code. I spent about 15 minutes working on a subroutine and this is what I came up with. (It’s still a work in progress… I’ll post later when I think it’s “complete”) To use it, copy and paste the code into Excel’s VBA Editor, highlight the table you want to convert, run the macro, and your output will be in the VBA Editor’s Immediate Window (View > Immediate Window).

% put this in your preamble
\usepackage{booktabs}
\usepackage{ctable}
% I used this to make the look of captions stand out
\usepackage[hang,small,bf]{caption}
Sub Table2Tabular()
    Dim Xn As Integer
    Dim Yn As Integer
 
    Dim Xi As Integer
    Dim Yi As Integer
 
    Dim strCells() As String
 
    Xn = Selection.Rows.Count
    Yn = Selection.Columns.Count
 
    ReDim strCells(Xn, Yn) As String
 
    Dim maxLength As Integer
 
    For Xi = 0 To Xn - 1
        For Yi = 0 To Yn - 1
            strCells(Xi, Yi) = Cells(Selection.Row + Xi, Selection.Column + Yi)
 
            If maxLength < Len(strCells(Xi, Yi)) + 9 Then maxLength = Len(strCells(Xi, Yi)) + 9
        Next
    Next
 
    Dim line As String
 
    Debug.Print "\begin{table}[tp]"
    Debug.Print vbTab & "\label{tab:Type label here.} \centering"
    line = vbTab & "\begin{tabular}{"
    For Xi = 1 To Xn
        If Selection.Columns(Xi).HorizontalAlignment = xlHAlignRight Then
            line = line & "r"
        ElseIf Selection.Columns(Xi).HorizontalAlignment = xlHAlignLeft Then
            line = line & "l"
        Else
            line = line & "c"
        End If
    Next
    line = line & "}"
    Debug.Print line
    line = ""
    Debug.Print vbTab & "\toprule"
 
    For Xi = 0 To Xn - 1
        For Yi = 0 To Yn - 1
            If Cells(Selection.Row + Xi, Selection.Column + Yi).Font.Bold = True Then
                If Yi = 0 Then
                    line = vbTab & vbTab & PadString(" \textbf{" & strCells(Xi, Yi) & "}", maxLength) & " &"
                ElseIf Yi = Yn - 1 Then
                    line = line & PadString(" \textbf{" & strCells(Xi, Yi) & "}", maxLength) & " \\"
                Else
                    line = line & PadString(" \textbf{" & strCells(Xi, Yi) & "}", maxLength) & " &"
                End If
            Else
                If Yi = 0 Then
                    line = vbTab & vbTab & " " & PadString(strCells(Xi, Yi), maxLength) & " &"
                ElseIf Yi = Yn - 1 Then
                    line = line & " " & PadString(strCells(Xi, Yi), maxLength) & " \\"
                Else
                    line = line & " " & PadString(strCells(Xi, Yi), maxLength) & " &"
                End If
            End If
        Next
 
        If Xi = 0 Then
            line = line & " \toprule"
        ElseIf Xi = Xn - 1 Then
            line = line & " \bottomrule"
        Else
            line = line & " \midrule"
        End If
 
        Debug.Print line
        line = ""
    Next
 
    Debug.Print vbTab & "\end{tabular}"
    Debug.Print vbTab & "\caption{Type caption here.}"
    Debug.Print "\end{table}"
End Sub
 
Function PadString(str As String, length As Integer) As String
    Dim padLength As Integer
    padLength = length - Len(str)
 
    Dim X As Integer
 
    For X = 1 To padLength
        str = str & " "
    Next
 
    PadString = str
End Function

A Word About Passwords

Password Haystacks

If you’ve never heard of or listened to Security Now on the TWiT network, it’s a weekly netcast about security related topics. Recently, in Episode #303, Steve Gibson, of Gibson Research Corporation, the co-host of Security Now, spoke about password strength. An observation he makes is that it is very easy to make an incredibly Read MoreRead More

If you’ve never heard of or listened to Security Now on the TWiT network, it’s a weekly netcast about security related topics. Recently, in Episode #303, Steve Gibson, of Gibson Research Corporation, the co-host of Security Now, spoke about password strength. An observation he makes is that it is very easy to make an incredibly strong password that is also easy to remember through the use of “padding.”

Gibson points out on his web site that D0g..................... is 95 times stronger than PrXyc.N(n4k77#L!eVdAfp9 as far as brute forcing goes, even though the stronger password is more easily memorable. While the second password has much high entropy (or randomness), an attacker (hopefully) wouldn’t have any knowledge of how you padded your password, so it makes little difference whether you add ++++++++ to your password, or ,7Hq3_9F, simply because an attacker would have to guess all possible combinations of characters in a brute force attack.

If you’re anything like me, you’re hanging your head in embarrassment for not thinking of this yourself.

On GRC there is a page called Password Haystacks where you can see a simple analysis of your password, and some estimated times for a brute forcer to crack different passwords:

Password Haystacks

Take-away:
Change your password from F0x to F0x*************** so you can sleep better tonight.

References:
GRC’s Password Haystacks

Welcome.

madfoxtechremote

Welcome to Mad Fox Tech. We do computer stuff.

Welcome to Mad Fox Tech. We do computer stuff.