settings API: how to create a multi checkbox with blog categories?

I had the same problem, and here what works for me:

function journal_check_cats_callback() {
    $options    = get_option('journal_theme_blog_2_col');
    $pag        = journal_theme_blog_2_col;
    $_cats      = get_terms( 'category' );
    $html="";

    foreach ($_cats as $term) {

        $checked = in_array($term->term_id, $options) ? 'checked="checked"' : '';
        $html .= sprintf( '<input type="checkbox" id="%1$s[%2$s]" name="%1$s[]" value="%2$s" %3$s />', $pag, $term->term_id, $checked );
        $html .= sprintf( '<label for="%1$s[%3$s]"> %2$s</label><br>', $pag, $term->name, $term->term_id );
    }

    $html .= sprintf( '<span class="description"> %s</label>', '' );

    echo $html;

}